Class: MLPClassifier

Multi-layer Perceptron classifier.

This model optimizes the log-loss function using LBFGS or stochastic gradient descent.

Python Reference

Constructors

new MLPClassifier()

new MLPClassifier(opts?): MLPClassifier

Parameters

ParameterTypeDescription
opts?object-
opts.activation?"identity" | "logistic" | "tanh" | "relu"Activation function for the hidden layer.
opts.alpha?numberStrength of the L2 regularization term. The L2 regularization term is divided by the sample size when added to the loss. For an example usage and visualization of varying regularization, see Varying regularization in Multi-layer Perceptron.
opts.batch_size?numberSize of minibatches for stochastic optimizers. If the solver is ‘lbfgs’, the classifier will not use minibatch. When set to “auto”, batch_size=min(200, n_samples).
opts.beta_1?numberExponential decay rate for estimates of first moment vector in adam, should be in [0, 1). Only used when solver=’adam’.
opts.beta_2?numberExponential decay rate for estimates of second moment vector in adam, should be in [0, 1). Only used when solver=’adam’.
opts.early_stopping?booleanWhether to use early stopping to terminate training when validation score is not improving. If set to true, it will automatically set aside 10% of training data as validation and terminate training when validation score is not improving by at least tol for n_iter_no_change consecutive epochs. The split is stratified, except in a multilabel setting. If early stopping is false, then the training stops when the training loss does not improve by more than tol for n_iter_no_change consecutive passes over the training set. Only effective when solver=’sgd’ or ‘adam’.
opts.epsilon?numberValue for numerical stability in adam. Only used when solver=’adam’.
opts.hidden_layer_sizes?anyThe ith element represents the number of neurons in the ith hidden layer.
opts.learning_rate?"constant" | "invscaling" | "adaptive"Learning rate schedule for weight updates.
opts.learning_rate_init?numberThe initial learning rate used. It controls the step-size in updating the weights. Only used when solver=’sgd’ or ‘adam’.
opts.max_fun?numberOnly used when solver=’lbfgs’. Maximum number of loss function calls. The solver iterates until convergence (determined by ‘tol’), number of iterations reaches max_iter, or this number of loss function calls. Note that number of loss function calls will be greater than or equal to the number of iterations for the MLPClassifier.
opts.max_iter?numberMaximum number of iterations. The solver iterates until convergence (determined by ‘tol’) or this number of iterations. For stochastic solvers (‘sgd’, ‘adam’), note that this determines the number of epochs (how many times each data point will be used), not the number of gradient steps.
opts.momentum?numberMomentum for gradient descent update. Should be between 0 and 1. Only used when solver=’sgd’.
opts.n_iter_no_change?numberMaximum number of epochs to not meet tol improvement. Only effective when solver=’sgd’ or ‘adam’.
opts.nesterovs_momentum?booleanWhether to use Nesterov’s momentum. Only used when solver=’sgd’ and momentum > 0.
opts.power_t?numberThe exponent for inverse scaling learning rate. It is used in updating effective learning rate when the learning_rate is set to ‘invscaling’. Only used when solver=’sgd’.
opts.random_state?numberDetermines random number generation for weights and bias initialization, train-test split if early stopping is used, and batch sampling when solver=’sgd’ or ‘adam’. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.shuffle?booleanWhether to shuffle samples in each iteration. Only used when solver=’sgd’ or ‘adam’.
opts.solver?"lbfgs" | "sgd" | "adam"The solver for weight optimization.
opts.tol?numberTolerance for the optimization. When the loss or score is not improving by at least tol for n_iter_no_change consecutive iterations, unless learning_rate is set to ‘adaptive’, convergence is considered to be reached and training stops.
opts.validation_fraction?numberThe proportion of training data to set aside as validation set for early stopping. Must be between 0 and 1. Only used if early_stopping is true.
opts.verbose?booleanWhether to print progress messages to stdout.
opts.warm_start?booleanWhen set to true, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. See the Glossary.

Returns MLPClassifier

Defined in generated/neural_network/MLPClassifier.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/neural_network/MLPClassifier.ts:21
_isInitializedbooleanfalsegenerated/neural_network/MLPClassifier.ts:20
_pyPythonBridgeundefinedgenerated/neural_network/MLPClassifier.ts:19
idstringundefinedgenerated/neural_network/MLPClassifier.ts:16
optsanyundefinedgenerated/neural_network/MLPClassifier.ts:17

Accessors

best_loss_

Get Signature

get best_loss_(): Promise<number>

The minimum loss reached by the solver throughout fitting. If early_stopping=True, this attribute is set to undefined. Refer to the best_validation_score_ fitted attribute instead.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:637


best_validation_score_

Get Signature

get best_validation_score_(): Promise<number>

The best validation score (i.e. accuracy score) that triggered the early stopping. Only available if early_stopping=True, otherwise the attribute is set to undefined.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:712


classes_

Get Signature

get classes_(): Promise<ArrayLike>

Class labels for each output.

Returns Promise<ArrayLike>

Defined in generated/neural_network/MLPClassifier.ts:589


coefs_

Get Signature

get coefs_(): Promise<any[]>

The ith element in the list represents the weight matrix corresponding to layer i.

Returns Promise<any[]>

Defined in generated/neural_network/MLPClassifier.ts:760


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/neural_network/MLPClassifier.ts:833


intercepts_

Get Signature

get intercepts_(): Promise<any[]>

The ith element in the list represents the bias vector corresponding to layer i + 1.

Returns Promise<any[]>

Defined in generated/neural_network/MLPClassifier.ts:783


loss_

Get Signature

get loss_(): Promise<number>

The current loss computed with the loss function.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:614


loss_curve_

Get Signature

get loss_curve_(): Promise<any[]>

The ith element in the list represents the loss at the ith iteration.

Returns Promise<any[]>

Defined in generated/neural_network/MLPClassifier.ts:662


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:808


n_iter_

Get Signature

get n_iter_(): Promise<number>

The number of iterations the solver has run.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:858


n_layers_

Get Signature

get n_layers_(): Promise<number>

Number of layers.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:881


n_outputs_

Get Signature

get n_outputs_(): Promise<number>

Number of outputs.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:906


out_activation_

Get Signature

get out_activation_(): Promise<string>

Name of the output activation function.

Returns Promise<string>

Defined in generated/neural_network/MLPClassifier.ts:931


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/neural_network/MLPClassifier.ts:187


t_

Get Signature

get t_(): Promise<number>

The number of training samples seen by the solver during fitting.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:737


validation_scores_

Get Signature

get validation_scores_(): Promise<any[]>

The score at each iteration on a held-out validation set. The score reported is the accuracy score. Only available if early_stopping=True, otherwise the attribute is set to undefined.

Returns Promise<any[]>

Defined in generated/neural_network/MLPClassifier.ts:687

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/neural_network/MLPClassifier.ts:239


fit()

fit(opts): Promise<any>

Fit the model to data matrix X and target(s) y.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe input data.
opts.y?ArrayLikeThe target values (class labels in classification, real numbers in regression).

Returns Promise<any>

Defined in generated/neural_network/MLPClassifier.ts:256


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/neural_network/MLPClassifier.ts:295


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/neural_network/MLPClassifier.ts:200


partial_fit()

partial_fit(opts): Promise<any>

Update the model with a single iteration over the given data.

Parameters

ParameterTypeDescription
optsobject-
opts.classes?any[]Classes across all calls to partial_fit. Can be obtained via np.unique(y_all), where y_all is the target vector of the entire dataset. This argument is required for the first call to partial_fit and can be omitted in the subsequent calls. Note that y doesn’t need to contain all labels in classes.
opts.X?ArrayLikeThe input data.
opts.y?ArrayLikeThe target values.

Returns Promise<any>

Defined in generated/neural_network/MLPClassifier.ts:329


predict()

predict(opts): Promise<ArrayLike>

Predict using the multi-layer perceptron classifier.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe input data.

Returns Promise<ArrayLike>

Defined in generated/neural_network/MLPClassifier.ts:371


predict_log_proba()

predict_log_proba(opts): Promise<ArrayLike[]>

Return the log of probability estimates.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The input data.

Returns Promise<ArrayLike[]>

Defined in generated/neural_network/MLPClassifier.ts:403


predict_proba()

predict_proba(opts): Promise<ArrayLike[]>

Probability estimates.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeThe input data.

Returns Promise<ArrayLike[]>

Defined in generated/neural_network/MLPClassifier.ts:437


score()

score(opts): Promise<number>

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample weights.
opts.X?ArrayLike[]Test samples.
opts.y?ArrayLikeTrue labels for X.

Returns Promise<number>

Defined in generated/neural_network/MLPClassifier.ts:471


set_partial_fit_request()

set_partial_fit_request(opts): Promise<any>

Request metadata passed to the partial_fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.classes?string | booleanMetadata routing for classes parameter in partial_fit.

Returns Promise<any>

Defined in generated/neural_network/MLPClassifier.ts:517


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/neural_network/MLPClassifier.ts:555