openstef.model.regressors package#
Submodules#
openstef.model.regressors.arima module#
This module contains the SARIMAX regressor wrapper around statsmodels implementation.
- class openstef.model.regressors.arima.ARIMAOpenstfRegressor(backtest_max_horizon=1440, order=(0, 0, 0), seasonal_order=(0, 0, 0, 0), trend=None)#
Bases:
OpenstfRegressor
Wrapper around statmodels implementation of (S)ARIMA(X) model.
The fit of an ARIMA statsmodels produces a result object which is used to perform the various computations around forecasting. (see https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.html)
To make a prediction, it needs to update the result object’s historic data, ie the past values of the target/endogenous data and the features/exogenous data, applying the fitted parameters to these new data unrelated to the original training data. This update can be performed by the method update_historic_data.
- In the following code, we use interchangeably the statmodels and scikit-learn terminology for the variables:
the features ‘x’ is equivalent to the exogenous data: ‘exog’ for short.
the target ‘y’ is equivalent to the endogenous data: ‘endog’ for short.
More information here https://www.statsmodels.org/stable/endog_exog.html.
- property can_predict_quantiles#
Indicates wether this model can make quantile predictions.
- property feature_names#
The names of he features used to train the model.
- fit(x, y, **kwargs)#
Fits the regressor.
- Parameters:
x – Feature matrix
y – Labels
kwargs – model-specific keywords
- Returns:
Fitted model
- predict(x, quantile=0.5, **kwargs)#
Makes a prediction. Only available after the model has been trained.
- Parameters:
x – Feature matrix
kwargs – model-specific keywords
- Returns:
Prediction
- predict_quantile(start, end, exog, quantile)#
Quantile prediction.
It relies on the parameters’ confidence intervals.
- Parameters:
start (int, str, or datetime, optional) – Zero-indexed observation number at which to start forecasting, i.e., the first forecast is start. Can also be a date string to parse or a datetime type. Default is the the zeroth observation.
end (int, str, or datetime, optional) – Zero-indexed observation number at which to end forecasting, i.e., the last forecast is end. Can also be a date string to parse or a datetime type. However, if the dates index does not have a fixed frequency, end must be an integer index if you want out of sample prediction. Default is the last observation in the sample.
exog (pd.DataFrame) – Exogenous data (features).
quantile (float) – The quantile for the confidence interval.
- Returns:
The quantile prediction.
- Return type:
pd.Serie
- score(x, y)#
Compute R2 score with backtesting strategy.
The backtest is performed by the Time Series cross-validator of scikit-learn which returns first k folds as train set and the (k+1)th fold as test set in the kth split. (see https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html)
It needs to update the historic data with (x_past, y_past) for each split.
- set_feature_importance()#
Because report needs ‘weight’ and ‘gain’ as importance metrics, we set the values to these names.
‘weight’ is corresponding to the coefficients values
‘gain’ is corresponding to the pvalue for the nullity test of each coefficient
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') ARIMAOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, quantile: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$') ARIMAOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
quantile (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
quantile
parameter inpredict
.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.
- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, x: bool | None | str = '$UNCHANGED$') ARIMAOpenstfRegressor #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- update_historic_data(x_past, y_past)#
Apply the fitted parameters to new data unrelated to the original training data. It’s a side-effect.
Creates a new result object using the current fitted parameters, applied to a completely new dataset that is assumed to be unrelated to the model’s original data. The new results can then be used for analysis or forecasting. It should be used before forecasting, to wedge the historic data just before the first forecast timestamp, with:
New observations from the modeled time-series process.
New observations of exogenous regressors.
- Parameters:
x_past (pd.DataFrame) – The exogenous (features) data.
y_past (pd.DataFrame) – The endogenous (target) data.
openstef.model.regressors.custom_regressor module#
This module defines the custom regressor.
- class openstef.model.regressors.custom_regressor.CustomOpenstfRegressor#
Bases:
OpenstfRegressor
A custom regressor allows to load any custom model that is not included with openSTEF.
- abstract classmethod objective()#
- Return type:
Type
[RegressorObjective
]
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') CustomOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, x: bool | None | str = '$UNCHANGED$') CustomOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- abstract static valid_kwargs()#
- Return type:
list
[str
]
- openstef.model.regressors.custom_regressor.create_custom_objective(custom_model_path)#
- openstef.model.regressors.custom_regressor.is_custom_type(model_type)#
- openstef.model.regressors.custom_regressor.load_custom_model(custom_model_path)#
Load the external custom model.
- Return type:
openstef.model.regressors.dazls module#
This module defines the DAZL model.
- class openstef.model.regressors.dazls.Dazls#
Bases:
BaseEstimator
DAZLS model.
The model carries out wind and solar power prediction for unseen target substations using training data from other substations with known components.
Any data-driven model can be plugged and used as the base for the domain and the adaptation model.
For a full reference, see: Teng, S.Y., van Nooten, C. C., van Doorn, J.M., Ottenbros, A., Huijbregts, M., Jansen, J.J. Improving Near Real-Time Predictions of Renewable Electricity Production at Substation Level (Submitted)
- fit(features, target)#
Fit the model.
In this function we scale the input of the domain and adaptation models of the DAZLS MODEL. Then we fit the two models. We separate the features into domain_model_input, adaptation_model_input and target, and we use them for the fitting and the training of the models.
- Parameters:
features – inputs for domain and adaptation model (domain_model_input, adaptation_model_input)
target – the expected output (y_train)
- predict(x)#
Make a prediction.
For the prediction we use the test data x. We use domain_model_input_columns and adaptation_model_input_columns to separate x in test data for domain model and adaptation model respectively.
- Parameters:
x (
array
) – domain_model_test_data, adaptation_model_test_dataprediction – The output prediction after both models.
- score(truth, prediction)#
Evaluation of the prediction’s output.
- Parameters:
truth – real values
prediction – predicted values
- Returns:
RMSE and R2 scores
- set_fit_request(*, features: bool | None | str = '$UNCHANGED$', target: bool | None | str = '$UNCHANGED$') Dazls #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
features (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
features
parameter infit
.target (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
target
parameter infit
.
- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, x: bool | None | str = '$UNCHANGED$') Dazls #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, prediction: bool | None | str = '$UNCHANGED$', truth: bool | None | str = '$UNCHANGED$') Dazls #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
prediction (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
prediction
parameter inscore
.truth (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
truth
parameter inscore
.
- Returns:
self – The updated object.
- Return type:
object
openstef.model.regressors.lgbm module#
- class openstef.model.regressors.lgbm.LGBMOpenstfRegressor(boosting_type='gbdt', num_leaves=31, max_depth=-1, learning_rate=0.1, n_estimators=100, subsample_for_bin=200000, objective=None, class_weight=None, min_split_gain=0.0, min_child_weight=0.001, min_child_samples=20, subsample=1.0, subsample_freq=0, colsample_bytree=1.0, reg_alpha=0.0, reg_lambda=0.0, random_state=None, n_jobs=-1, silent='warn', importance_type='split', **kwargs)#
Bases:
LGBMRegressor
,OpenstfRegressor
LGBM Regressor which implements the Openstf regressor API.
- property can_predict_quantiles#
Attribute that indicates if the model predict particular quantiles.
e.g. XGBQuantileOpenstfRegressor
- property feature_names#
Retrieve the model input feature names.
- Returns:
The list of feature names
- gain_importance_name = 'gain'#
- set_fit_request(*, callbacks: bool | None | str = '$UNCHANGED$', categorical_feature: bool | None | str = '$UNCHANGED$', early_stopping_rounds: bool | None | str = '$UNCHANGED$', eval_init_score: bool | None | str = '$UNCHANGED$', eval_metric: bool | None | str = '$UNCHANGED$', eval_names: bool | None | str = '$UNCHANGED$', eval_sample_weight: bool | None | str = '$UNCHANGED$', eval_set: bool | None | str = '$UNCHANGED$', feature_name: bool | None | str = '$UNCHANGED$', init_model: bool | None | str = '$UNCHANGED$', init_score: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$', verbose: bool | None | str = '$UNCHANGED$') LGBMOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
callbacks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
callbacks
parameter infit
.categorical_feature (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
categorical_feature
parameter infit
.early_stopping_rounds (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
early_stopping_rounds
parameter infit
.eval_init_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_init_score
parameter infit
.eval_metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_metric
parameter infit
.eval_names (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_names
parameter infit
.eval_sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_sample_weight
parameter infit
.eval_set (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_set
parameter infit
.feature_name (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
feature_name
parameter infit
.init_model (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
init_model
parameter infit
.init_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
init_score
parameter infit
.sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter infit
.verbose (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
verbose
parameter infit
.
- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, num_iteration: bool | None | str = '$UNCHANGED$', pred_contrib: bool | None | str = '$UNCHANGED$', pred_leaf: bool | None | str = '$UNCHANGED$', raw_score: bool | None | str = '$UNCHANGED$', start_iteration: bool | None | str = '$UNCHANGED$') LGBMOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
num_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
num_iteration
parameter inpredict
.pred_contrib (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
pred_contrib
parameter inpredict
.pred_leaf (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
pred_leaf
parameter inpredict
.raw_score (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
raw_score
parameter inpredict
.start_iteration (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
start_iteration
parameter inpredict
.
- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') LGBMOpenstfRegressor #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
- weight_importance_name = 'split'#
openstef.model.regressors.linear module#
This module contains the linear regressor.
- class openstef.model.regressors.linear.LinearOpenstfRegressor(missing_values=nan, imputation_strategy=None, fill_value=0)#
Bases:
LinearRegressor
,OpenstfRegressor
Linear Regressor which implements the Openstf regressor API.
- property can_predict_quantiles#
Indicates wether this model can make quantile predictions.
- property feature_names#
The names of he features used to train the model.
- fit(x, y, **kwargs)#
Fit model.
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') LinearOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, x: bool | None | str = '$UNCHANGED$') LinearOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- class openstef.model.regressors.linear.LinearRegressor(missing_values=nan, imputation_strategy=None, fill_value=0)#
Bases:
MissingValuesHandler
Linear Regressor wrapped in the metamodel MissingValuesHandler.
This regressor can handle missing values by imputation strategy.
- Parameters:
missing_values – int, float, str, np.nan or None, default=np.nan The placeholder for the missing values. All occurrences of missing_values will be imputed. For pandas’ dataframes with nullable integer dtypes with missing values, missing_values should be set to np.nan, since pd.NA will be converted to np.nan.
imputation_strategy – str, default=None The imputation strategy. - If None no imputation is performed. - If “mean”, then replace missing values using the mean along each column. Can only be used with numeric data. - If “median”, then replace missing values using the median along each column. Can only be used with numeric data. - If “most_frequent”, then replace missing using the most frequent value along each column. Can be used with strings or numeric data. If there is more than one such value, only the smallest is returned. - If “constant”, then replace missing values with fill_value. Can be used with strings or numeric data.
fill_value – str or numerical value, default=None When strategy == “constant”, fill_value is used to replace all occurrences of missing_values. If left to the default, fill_value will be 0 when imputing numerical data and “missing_value” for strings or object data types.
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') LinearRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, x: bool | None | str = '$UNCHANGED$') LinearRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') LinearRegressor #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter inscore
.- Returns:
self – The updated object.
- Return type:
object
openstef.model.regressors.proloaf module#
openstef.model.regressors.regressor module#
- class openstef.model.regressors.regressor.OpenstfRegressor#
Bases:
BaseEstimator
This class defines the interface to which all ML models within OpenSTEF should adhere.
Required methods are indicated by abstractmethods, for which concrete implementations of ML models should have a definition. Common functionality which is required for the automated pipelines in OpenSTEF is defined in this class.
- abstract property can_predict_quantiles: bool#
Attribute that indicates if the model predict particular quantiles.
e.g. XGBQuantileOpenstfRegressor
- Return type:
bool
- abstract property feature_names: list#
Retrieve the model input feature names.
- Return type:
list
- Returns:
The list of feature names
- abstract fit(x, y, **kwargs)#
Fits the regressor.
- Parameters:
x (
array
) – Feature matrixy (
array
) – Labelskwargs – model-specific keywords
- Return type:
RegressorMixin
- Returns:
Fitted model
- abstract predict(x, **kwargs)#
Makes a prediction. Only available after the model has been trained.
- Parameters:
x (
DataFrame
) – Feature matrixkwargs – model-specific keywords
- Return type:
array
- Returns:
Prediction
- score(X, y)#
Makes score method from RegressorMixin available.
- set_feature_importance()#
Get feature importance.
- Return type:
Optional
[DataFrame
]- Returns:
DataFrame with feature importance.
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') OpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, x: bool | None | str = '$UNCHANGED$') OpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.- Returns:
self – The updated object.
- Return type:
object
openstef.model.regressors.xgb module#
- class openstef.model.regressors.xgb.XGBOpenstfRegressor(*, objective='reg:squarederror', **kwargs)#
Bases:
XGBRegressor
,OpenstfRegressor
XGB Regressor which implements the Openstf regressor API.
- property can_predict_quantiles#
Attribute that indicates if the model predict particular quantiles.
e.g. XGBQuantileOpenstfRegressor
- property feature_names#
Retrieve the model input feature names.
- Returns:
The list of feature names
- gain_importance_name = 'total_gain'#
- set_fit_request(*, base_margin: bool | None | str = '$UNCHANGED$', base_margin_eval_set: bool | None | str = '$UNCHANGED$', callbacks: bool | None | str = '$UNCHANGED$', early_stopping_rounds: bool | None | str = '$UNCHANGED$', eval_metric: bool | None | str = '$UNCHANGED$', eval_set: bool | None | str = '$UNCHANGED$', feature_weights: bool | None | str = '$UNCHANGED$', sample_weight: bool | None | str = '$UNCHANGED$', sample_weight_eval_set: bool | None | str = '$UNCHANGED$', verbose: bool | None | str = '$UNCHANGED$', xgb_model: bool | None | str = '$UNCHANGED$') XGBOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
base_margin (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
base_margin
parameter infit
.base_margin_eval_set (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
base_margin_eval_set
parameter infit
.callbacks (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
callbacks
parameter infit
.early_stopping_rounds (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
early_stopping_rounds
parameter infit
.eval_metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_metric
parameter infit
.eval_set (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
eval_set
parameter infit
.feature_weights (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
feature_weights
parameter infit
.sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight
parameter infit
.sample_weight_eval_set (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weight_eval_set
parameter infit
.verbose (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
verbose
parameter infit
.xgb_model (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
xgb_model
parameter infit
.
- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, base_margin: bool | None | str = '$UNCHANGED$', iteration_range: bool | None | str = '$UNCHANGED$', ntree_limit: bool | None | str = '$UNCHANGED$', output_margin: bool | None | str = '$UNCHANGED$', validate_features: bool | None | str = '$UNCHANGED$') XGBOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
base_margin (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
base_margin
parameter inpredict
.iteration_range (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
iteration_range
parameter inpredict
.ntree_limit (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
ntree_limit
parameter inpredict
.output_margin (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
output_margin
parameter inpredict
.validate_features (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
validate_features
parameter inpredict
.
- Returns:
self – The updated object.
- Return type:
object
- weight_importance_name = 'weight'#
openstef.model.regressors.xgb_quantile module#
- class openstef.model.regressors.xgb_quantile.XGBQuantileOpenstfRegressor(quantiles=(0.9, 0.5, 0.1), gamma=0.0, colsample_bytree=1.0, subsample=1.0, min_child_weight=1, max_depth=6, learning_rate=0.3, alpha=0.0, max_delta_step=0)#
Bases:
OpenstfRegressor
- property can_predict_quantiles#
Attribute that indicates if the model predict particular quantiles.
e.g. XGBQuantileOpenstfRegressor
- property feature_names#
Retrieve the model input feature names.
- Returns:
The list of feature names
- fit(x, y, **kwargs)#
Fits xgb quantile model.
- Parameters:
x (
array
) – Feature matrixy (
array
) – Labels
- Return type:
- Returns:
Fitted XGBQuantile model
- classmethod get_feature_importances_from_booster(booster)#
Gets feauture importances from a XGB booster.
This is based on the feature_importance_ property defined in: dmlc/xgboost.
- Parameters:
booster (
Booster
) – Booster object, most of the times the median model (quantile=0.5) is preferred- Return type:
ndarray
- Returns:
Ndarray with normalized feature importances.
- predict(x, quantile=0.5)#
Makes a prediction for a desired quantile.
- Parameters:
x (
array
) – Feature matrixquantile (
float
) – Quantile for which a prediciton is desired, note that only quantile are available for which a model is trained, and that this is a quantile-model specific keyword
- Return type:
array
- Returns:
Prediction
- Raises:
ValueError in case no model is trained for the requested quantile –
- set_fit_request(*, x: bool | None | str = '$UNCHANGED$') XGBQuantileOpenstfRegressor #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter infit
.- Returns:
self – The updated object.
- Return type:
object
- set_predict_request(*, quantile: bool | None | str = '$UNCHANGED$', x: bool | None | str = '$UNCHANGED$') XGBQuantileOpenstfRegressor #
Request metadata passed to the
predict
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topredict
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it topredict
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.- Parameters:
quantile (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
quantile
parameter inpredict
.x (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x
parameter inpredict
.
- Returns:
self – The updated object.
- Return type:
object