modrover.learner#
- class modrover.learner.Learner(model_class, obs, main_param, param_specs, weights='weights', get_score=<function get_rmse>)[source]#
Bases:
object
Individual learner class for one specific covariate configuration.
- Parameters:
model_class (type) – Regmod model constructor
obs (str) – Name corresponding to the observation column in the data frame
main_param (str) – The main parameter we are exploring. This is aligned with the
modrover.rover.Rover
class.param_specs (dict[str, dict]) – Parameter settings for the regmod model
weights (str) – Name corresponding to the weights column in the data frame
get_score (Callable) – Function that evaluate the score of of the model
- property coef: NDArray | None#
Coefficients in the regmod model.
- property vcov: NDArray | None#
Variance-covarianace matrix for the coefficients in the regmod model.
- fit(data, holdouts=None, **optimizer_options)[source]#
Fit a set of models on a series of holdout datasets.
This method will fit a model over k folds of the dataset, where k is the length of the provided holdouts list. It is up to the user to decide the train-test splits for each holdout column.
On each fold of the dataset, the trained model will predict out on the validation set and obtain a evaluate. The averaged evaluate across all folds becomes the model’s overall score.
Finally, a model is trained with all data in order to generate the final coefficients.
- Parameters:
data (DataFrame) – A dataframe containing the training data
holdouts (list[str] | None) – Which column names to iterate over for cross validation. If it is None, insample performance score will be used to evaluate the model.
**optimizer_options – Extra options for the optimizer.
- Return type:
None
- predict(data, model=None, return_ui=False, alpha=0.05)[source]#
Generate prediction using regmod model. This function will return predictions for the
main_param
with given data.- Parameters:
data (DataFrame) – A dataset to generate predictions from
model (Model | None) – A fitted RegmodModel. If it is
None
, will use the overall model rather than the cross-validation model.return_ui (bool) – If
return_ui=True
, a matrix will be returned. The first row is the point prediction, second and thrid rows are the lower and upper bound of the prediction.alpha (float) – When
return_ui=True
, function will return (1 -alpha
) uncertainty interval. By default,alpha=0.05
.
- Return type:
NDArray
- evaluate(data, model=None)[source]#
Given a model and a test set, generate a performance score.
Score is based on the provided evaluation metric, comparing the difference between observed and predicted values.
- Parameters:
data (DataFrame) – The data set to generate predictions from
model (Model | None) – The fitted model to set predictions on. If
None
will use the overall model rather than the cross-validation model.
- Return type:
float