PassiveAggressiveClassifier
Passive Aggressive Classifier.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new PassiveAggressiveClassifier(opts?: object): PassiveAggressiveClassifier;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.C? | number | Maximum step size (regularization). Defaults to 1.0. Default Value 1 |
opts.average? | number | boolean | When set to true , computes the averaged SGD weights and stores the result in the coef\_ attribute. If set to an int greater than 1, averaging will begin once the total number of samples seen reaches average. So average=10 will begin averaging after seeing 10 samples. Default Value false |
opts.class_weight? | any | Preset for the class_weight fit parameter. Weights associated with classes. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n\_samples / (n\_classes \* np.bincount(y)) . |
opts.early_stopping? | boolean | Whether to use early stopping to terminate training when validation. score is not improving. If set to true , it will automatically set aside a stratified fraction 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. Default Value false |
opts.fit_intercept? | boolean | Whether the intercept should be estimated or not. If false , the data is assumed to be already centered. Default Value true |
opts.loss? | string | The loss function to be used: hinge: equivalent to PA-I in the reference paper. squared_hinge: equivalent to PA-II in the reference paper. Default Value 'hinge' |
opts.max_iter? | number | The maximum number of passes over the training data (aka epochs). It only impacts the behavior in the fit method, and not the partial\_fit method. Default Value 1000 |
opts.n_iter_no_change? | number | Number of iterations with no improvement to wait before early stopping. Default Value 5 |
opts.n_jobs? | number | The number of CPUs to use to do the OVA (One Versus All, for multi-class problems) computation. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details. |
opts.random_state? | number | Used to shuffle the training data, when shuffle is set to true . Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.shuffle? | boolean | Whether or not the training data should be shuffled after each epoch. Default Value true |
opts.tol? | number | The stopping criterion. If it is not undefined , the iterations will stop when (loss > previous_loss - tol). Default Value 0.001 |
opts.validation_fraction? | number | The 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 . Default Value 0.1 |
opts.verbose? | number | The verbosity level. Default Value 0 |
opts.warm_start? | boolean | When set to true , reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. See the Glossary. Repeatedly calling fit or partial_fit when warm_start is true can result in a different solution than when calling fit a single time because of the way the data is shuffled. Default Value false |
Returns
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:23 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:21 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:20 (opens in a new tab)
_py
PythonBridge
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:19 (opens in a new tab)
id
string
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:16 (opens in a new tab)
opts
any
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:17 (opens in a new tab)
Accessors
classes_
The unique classes labels.
Signature
classes_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:669 (opens in a new tab)
coef_
Weights assigned to the features.
Signature
coef_(): Promise<ArrayLike[][]>;
Returns
Promise
<ArrayLike
[][]>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:534 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:615 (opens in a new tab)
intercept_
Constants in decision function.
Signature
intercept_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:561 (opens in a new tab)
loss_function_
Loss function used by the algorithm.
Signature
loss_function_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:723 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:588 (opens in a new tab)
n_iter_
The actual number of iterations to reach the stopping criterion. For multiclass fits, it is the maximum over every binary fit.
Signature
n_iter_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:642 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:133 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:137 (opens in a new tab)
t_
Number of weight updates performed during training. Same as (n\_iter\_ \* n\_samples + 1)
.
Signature
t_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:696 (opens in a new tab)
Methods
decision_function()
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
Signature
decision_function(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The data matrix for which we want to get the confidence scores. |
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:227 (opens in a new tab)
densify()
Convert coefficient matrix to dense array format.
Converts the coef\_
member (back) to a numpy.ndarray. This is the default format of coef\_
and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
Signature
densify(opts: object): Promise<any>;
Parameters
Name | Type |
---|---|
opts | object |
Returns
Promise
<any
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:267 (opens in a new tab)
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:208 (opens in a new tab)
fit()
Fit linear model with Passive Aggressive algorithm.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training data. |
opts.coef_init? | ArrayLike [] | The initial coefficients to warm-start the optimization. |
opts.intercept_init? | ArrayLike | The initial intercept to warm-start the optimization. |
opts.y? | ArrayLike | Target values. |
Returns
Promise
<any
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:297 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:146 (opens in a new tab)
partial_fit()
Fit linear model with Passive Aggressive algorithm.
Signature
partial_fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Subset of the training data. |
opts.classes? | ArrayLike | Classes across all calls to partial_fit. Can be obtained by 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.y? | ArrayLike | Subset of the target values. |
Returns
Promise
<any
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:357 (opens in a new tab)
predict()
Predict class labels for samples in X.
Signature
predict(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | The data matrix for which we want to get the predictions. |
Returns
Promise
<ArrayLike
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:409 (opens in a new tab)
score()
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.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Test samples. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True labels for X . |
Returns
Promise
<number
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:449 (opens in a new tab)
sparsify()
Convert coefficient matrix to sparse format.
Converts the coef\_
member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The intercept\_
member is not converted.
Signature
sparsify(opts: object): Promise<any>;
Parameters
Name | Type |
---|---|
opts | object |
Returns
Promise
<any
>
Defined in: generated/linear_model/PassiveAggressiveClassifier.ts:504 (opens in a new tab)