macrosynergy.learning.forecasting.ensemble#
- class VotingClassifier(estimators, voting='hard', weights=None, n_jobs=None, flatten_transform=True, verbose=False)[source]#
Bases:
VotingClassifierClassification model that votes on the predictions of many classifiers.
- Parameters:
estimators (list of (str, estimator) tuples) – List of (name, estimator) tuples that are used to fit the model.
voting ({'hard', 'soft'}, default='hard') – If ‘hard’, uses predicted class labels for majority rule voting. If ‘soft’, predicts the class label based on the argmax of the sums of the predicted probabilities, which is recommended for an ensemble of well-calibrated classifiers.
weights (array-like of shape (n_estimators,), default=None) – Sequence of weights to assign to models. If None, models are weighted equally.
n_jobs (int, default=None) – The number of jobs to run in parallel for fit. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.
flatten_transform (bool, default=True) – Affects shape of transform output only when voting=’soft’. If True, the transform method returns a matrix with shape (n_samples, n_classes*n_classifiers). If False, the shape is (n_classifiers, n_samples, n_classes).
verbose (bool, default=False) – If True, the time elapsed while fitting will be printed as model trains.
Notes
This class calculates feature importances as the average of the feature importances of the base estimators.
- fit(X, y, sample_weight=None, **fit_params)[source]#
Fit the estimators.
- Parameters:
X (pd.DataFrame or np.ndarray) – Pandas dataframe or numpy array of input features.
y (pd.Series or pd.DataFrame or np.ndarray) – Pandas series, dataframe or numpy array of targets associated with each sample in X.
- set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') VotingClassifier#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif 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.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') VotingClassifier#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif 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.
- class VotingRegressor(estimators, weights=None, verbose=False)[source]#
Bases:
VotingRegressorRegression model that averages the predictions of many regression models.
- Parameters:
estimators (list of (str, estimator) tuples) – List of (name, estimator) tuples that are used to fit the model.
weights (array-like of shape (n_estimators,), default=None) – Sequence of weights to assign to models. If None, models are weighted equally.
verbose (bool, default=False) – If True, the time elapsed while fitting will be printed as model trains.
Notes
This class calculates feature importances as the average of the feature importances of the base estimators.
- fit(X, y, **fit_params)[source]#
Fit the estimators.
- Parameters:
X (pd.DataFrame or np.ndarray) – Pandas dataframe or numpy array of input features.
y (pd.Series or pd.DataFrame or np.ndarray) – Pandas series, dataframe or numpy array of targets associated with each sample in X.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') VotingRegressor#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif 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.