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.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new LinearDiscriminantAnalysis(opts?: object): LinearDiscriminantAnalysis;
Parameters
Name | 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. |
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. Default Value 'svd' |
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. Default Value false |
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’. Default Value 0.0001 |
Returns
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:27 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:25 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:24 (opens in a new tab)
_py
PythonBridge
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:23 (opens in a new tab)
id
string
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:20 (opens in a new tab)
opts
any
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:21 (opens in a new tab)
Accessors
classes_
Unique class labels.
Signature
classes_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:797 (opens in a new tab)
coef_
Weight vector(s).
Signature
coef_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:581 (opens in a new tab)
covariance_
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
.
Signature
covariance_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:635 (opens in a new tab)
explained_variance_ratio_
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.
Signature
explained_variance_ratio_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:662 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:851 (opens in a new tab)
intercept_
Intercept term.
Signature
intercept_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:608 (opens in a new tab)
means_
Class-wise means.
Signature
means_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:689 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:824 (opens in a new tab)
priors_
Class priors (sum to 1).
Signature
priors_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:716 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:75 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:79 (opens in a new tab)
scalings_
Scaling of the features in the space spanned by the class centroids. Only available for ‘svd’ and ‘eigen’ solvers.
Signature
scalings_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:743 (opens in a new tab)
xbar_
Overall mean. Only present if solver is ‘svd’.
Signature
xbar_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:770 (opens in a new tab)
Methods
decision_function()
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.
Signature
decision_function(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Array of samples (test vectors). |
Returns
Promise
<ArrayLike
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:161 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:142 (opens in a new tab)
fit()
Fit the Linear Discriminant Analysis model.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Training data. |
opts.y? | ArrayLike | Target values. |
Returns
Promise
<any
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:199 (opens in a new tab)
fit_transform()
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit\_params
and returns a transformed version of X
.
Signature
fit_transform(opts: object): Promise<any[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input samples. |
opts.fit_params? | any | Additional fit parameters. |
opts.y? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns
Promise
<any
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:245 (opens in a new tab)
get_feature_names_out()
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"\]
.
Signature
get_feature_names_out(opts: object): Promise<any>;
Parameters
Name | 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:299 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:88 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:337 (opens in a new tab)
predict_log_proba()
Estimate log probability.
Signature
predict_log_proba(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:374 (opens in a new tab)
predict_proba()
Estimate probability.
Signature
predict_proba(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:412 (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/discriminant_analysis/LinearDiscriminantAnalysis.ts:452 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:505 (opens in a new tab)
transform()
Project data to maximize class separation.
Signature
transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Input data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/discriminant_analysis/LinearDiscriminantAnalysis.ts:543 (opens in a new tab)