ensemble.BaggingClassifier

A Bagging classifier is an ensemble meta-estimator that fits base classifiers each on random subsets of the original dataset and then aggregate their individual predictions by voting to form a final prediction

Usage

const classifier = new BaggingClassifier({
 baseEstimator: LogisticRegression,
 maxSamples: 1.0,
});
const X = [[1], [2], [3], [4], [5]];
const y = [1, 1, 1, 1, 1];
classifier.fit(X, y);
classifier.predict(X);

Constructors

Methods

Constructors


constructor

new BaggingClassifier(__namedParameters: `object`)

Defined in ensemble/bagging.ts:38

Parameters:

ParamTypeDefaultDescription
options.baseEstimatoranyDecisionTreeClassifierThe model that will be used as a basis of ensemble.
options.bootstrapFeaturesbooleanfalseWhether features are drawn with replacement.
options.bootstrapSamplesbooleanfalseWhether samples are drawn with replacement. If false, sampling without replacement is performed.
options.estimatorOptionsanyconstructor options for BaseEstimator.
options.maxFeaturesnumber1The number of features to draw from X to train each base estimator. Is used in conjunction with @param maxFeaturesIsFloating If maxFeaturesIsFloating is false, then draw max_features features. If maxFeaturesIsFloating is true, then draw max_features * shape(X)[1] features.
options.maxFeaturesIsFloatingbooleantrueif true, draw maxFeatures samples
options.maxSamplesnumber1The number of samples to draw from X to train each base estimator. Is used in conjunction with maxSamplesIsFloating. If @param maxSamplesIsFloating is false, then draw maxSamples samples. If @param maxSamplesIsFloating is true, then draw max_samples * shape(X)[0] samples.
options.maxSamplesIsFloatingbooleantrueif true, draw maxSamples samples
options.numEstimatorsnumber10The number of estimators that will be used in ensemble.

Returns: BaggingClassifier

Methods


λ fit

Builds an ensemble of base classifier from the training set (X, y).

Defined in ensemble/bagging.ts:108

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like or sparse matrix of shape = [n_samples, n_features]
ynumber[]nullarray-like, shape = [n_samples]

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in ensemble/bagging.ts:193

Parameters:

ParamTypeDefaultDescription
options.baseEstimatorany
options.bootstrapFeaturesboolean
options.bootstrapSamplesboolean
options.estimatorOptionsany
options.estimatorsany[]
options.estimatorsFeaturesnumber[][]
options.maxFeaturesnumber
options.maxFeaturesIsFloatingboolean
options.maxSamplesnumber
options.maxSamplesIsFloatingboolean
options.numEstimatorsnumber

Returns:

void

λ predict

Predict class for each row in X.

Predictions are formed using the majority voting.

Defined in ensemble/bagging.ts:137

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like or sparse matrix of shape = [n_samples, n_features]

Returns:

number[]

λ toJSON

Get the model details in JSON format

Defined in ensemble/bagging.ts:161

Returns:

ParamTypeDescription
baseEstimatoranyundefined
bootstrapFeaturesbooleanundefined
bootstrapSamplesbooleanundefined
estimatorOptionsanyundefined
estimatorsany[]undefined
estimatorsFeaturesnumber[][]undefined
maxFeaturesnumberundefined
maxFeaturesIsFloatingbooleanundefined
maxSamplesnumberundefined
maxSamplesIsFloatingbooleanundefined
numEstimatorsnumberundefined