Class: LinearDiscriminantAnalysis
Linear Discriminant Analysis.
A classifier with a linear decision boundary, generated by fitting class conditional densities to the data and using Bayes’ rule.
The model fits a Gaussian density to each class, assuming that all classes share the same covariance matrix.
The fitted model can also be used to reduce the dimensionality of the input by projecting it to the most discriminative directions, using the transform
method.
Constructors
new LinearDiscriminantAnalysis()
new LinearDiscriminantAnalysis(
opts
?):LinearDiscriminantAnalysis
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.covariance_estimator ? | any | If not undefined , covariance_estimator is used to estimate the covariance matrices instead of relying on the empirical covariance estimator (with potential shrinkage). The object should have a fit method and a covariance_ attribute like the estimators in sklearn.covariance . if undefined the shrinkage parameter drives the estimate. This should be left to undefined if shrinkage is used. Note that covariance_estimator works only with ‘lsqr’ and ‘eigen’ solvers. |
opts.n_components ? | number | Number of components (<= min(n_classes - 1, n_features)) for dimensionality reduction. If undefined , will be set to min(n_classes - 1, n_features). This parameter only affects the transform method. For a usage example, see Comparison of LDA and PCA 2D projection of Iris dataset. |
opts.priors ? | ArrayLike | The class prior probabilities. By default, the class proportions are inferred from the training data. |
opts.shrinkage ? | number | "auto" | None: no shrinkage (default). |
opts.solver ? | "svd" | "lsqr" | "eigen" | ‘svd’: Singular value decomposition (default). Does not compute the covariance matrix, therefore this solver is recommended for data with a large number of features. |
opts.store_covariance ? | boolean | If true , explicitly compute the weighted within-class covariance matrix when solver is ‘svd’. The matrix is always computed and stored for the other solvers. |
opts.tol ? | number | Absolute threshold for a singular value of X to be considered significant, used to estimate the rank of X. Dimensions whose singular values are non-significant are discarded. Only used if solver is ‘svd’. |
Returns LinearDiscriminantAnalysis
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:25 |
_isInitialized | boolean | false | generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:24 |
_py | PythonBridge | undefined | generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:23 |
id | string | undefined | generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:20 |
opts | any | undefined | generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:21 |
Accessors
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
Unique class labels.
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:839
coef_
Get Signature
get coef_():
Promise
<ArrayLike
>
Weight vector(s).
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:623
covariance_
Get Signature
get covariance_():
Promise
<ArrayLike
[]>
Weighted within-class covariance matrix. It corresponds to sum_k prior_k \* C_k
where C_k
is the covariance matrix of the samples in class k
. The C_k
are estimated using the (potentially shrunk) biased estimator of covariance. If solver is ‘svd’, only exists when store_covariance
is true
.
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:677
explained_variance_ratio_
Get Signature
get explained_variance_ratio_():
Promise
<ArrayLike
>
Percentage of variance explained by each of the selected components. If n_components
is not set then all components are stored and the sum of explained variances is equal to 1.0. Only available when eigen or svd solver is used.
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:704
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/discriminant_analysis/LinearDiscriminantAnalysis.ts:893
intercept_
Get Signature
get intercept_():
Promise
<ArrayLike
>
Intercept term.
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:650
means_
Get Signature
get means_():
Promise
<ArrayLike
[]>
Class-wise means.
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:731
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:866
priors_
Get Signature
get priors_():
Promise
<ArrayLike
>
Class priors (sum to 1).
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:758
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:77
scalings_
Get Signature
get scalings_():
Promise
<ArrayLike
[]>
Scaling of the features in the space spanned by the class centroids. Only available for ‘svd’ and ‘eigen’ solvers.
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:785
xbar_
Get Signature
get xbar_():
Promise
<ArrayLike
>
Overall mean. Only present if solver is ‘svd’.
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:812
Methods
decision_function()
decision_function(
opts
):Promise
<ArrayLike
>
Apply decision function to an array of samples.
The decision function is equal (up to a constant factor) to the log-posterior of the model, i.e. log p(y \= k | x)
. In a binary classification setting this instead corresponds to the difference log p(y \= 1 | x) \- log p(y \= 0 | x)
. See Mathematical formulation of the LDA and QDA classifiers.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | Array of samples (test vectors). |
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:152
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/discriminant_analysis/LinearDiscriminantAnalysis.ts:133
fit()
fit(
opts
):Promise
<any
>
Fit the Linear Discriminant Analysis model.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | Training data. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:188
fit_transform()
fit_transform(
opts
):Promise
<any
[]>
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit_params
and returns a transformed version of X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns Promise
<any
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:231
get_feature_names_out()
get_feature_names_out(
opts
):Promise
<any
>
Get output feature names for transformation.
The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: \["class_name0", "class_name1", "class_name2"\]
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Only used to validate feature names with the names seen in fit . |
Returns Promise
<any
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:279
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:317
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:90
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict class labels for samples in X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The data matrix for which we want to get the predictions. |
Returns Promise
<ArrayLike
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:353
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
Estimate log probability.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | Input data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:389
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Estimate probability.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | Input data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:425
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:463
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:511
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:551
transform()
transform(
opts
):Promise
<ArrayLike
[]>
Project data to maximize class separation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | Input data. |
Returns Promise
<ArrayLike
[]>
Defined in generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:587