compare_classifiers.ensemble_predict

Attributes

METHOD_ERROR

Functions

ensemble_predict(estimators, X_train, y_train, ...)

predict class for test data with provided estimators and whether predicting through Voting or Stacking

Module Contents

compare_classifiers.ensemble_predict.METHOD_ERROR = 'fourth parameter has to be a string of two possible values: "voting" and "stacking"'
compare_classifiers.ensemble_predict.ensemble_predict(estimators, X_train, y_train, ensemble_method, test_data)[source]

predict class for test data with provided estimators and whether predicting through Voting or Stacking

Parameters:
  • estimators (list of tuples) – A list of (name, estimator) tuples, consisting of individual estimators to be processed through the voting or stacking classifying ensemble. Each tuple contains a string: name/label of estimator, and a model: the estimator, which implements the scikit-learn API (fit, predict, etc.).

  • X_train (Pandas data frame or Numpy array) – Data frame containing training data along with n features or ndarray with no feature names.

  • y_train (Pandas series or Numpy array) – Target class labels for data in X_train.

  • ensemble_method (str) – Whether prediction is made through voting or stacking. Possible values are: ‘voting’ or ‘stacking’.

  • test_data (Pandas data frame) – Data to make predictions on.

Returns:

Predicted class labels for test_data.

Return type:

Numpy array

Examples

>>> estimators = [
...     ('rf', RandomForestClassifier(n_estimators=10, random_state=42)),
...     ('svm', make_pipeline(StandardScaler(), LinearSVC(random_state=42)))
... ]
>>> ensemble_predict(estimators, X, y, unseen_data, 'voting')