SparseCoder
Sparse coding.
Finds a sparse representation of data against a fixed, precomputed dictionary.
Each row of the result is the solution to a sparse coding problem. The goal is to find a sparse array code
such that:
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new SparseCoder(opts?: object): SparseCoder;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.dictionary? | ArrayLike [] | The dictionary atoms used for sparse coding. Lines are assumed to be normalized to unit norm. |
opts.n_jobs? | number | Number of parallel jobs to run. 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.positive_code? | boolean | Whether to enforce positivity when finding the code. Default Value false |
opts.split_sign? | boolean | Whether to split the sparse feature vector into the concatenation of its negative part and its positive part. This can improve the performance of downstream classifiers. Default Value false |
opts.transform_algorithm? | "threshold" | "lars" | "lasso_lars" | "lasso_cd" | "omp" | Algorithm used to transform the data: Default Value 'omp' |
opts.transform_alpha? | number | If algorithm='lasso\_lars' or algorithm='lasso\_cd' , alpha is the penalty applied to the L1 norm. If algorithm='threshold' , alpha is the absolute value of the threshold below which coefficients will be squashed to zero. If algorithm='omp' , alpha is the tolerance parameter: the value of the reconstruction error targeted. In this case, it overrides n\_nonzero\_coefs . If undefined , default to 1. |
opts.transform_max_iter? | number | Maximum number of iterations to perform if algorithm='lasso\_cd' or lasso\_lars . Default Value 1000 |
opts.transform_n_nonzero_coefs? | number | Number of nonzero coefficients to target in each column of the solution. This is only used by algorithm='lars' and algorithm='omp' and is overridden by alpha in the omp case. If undefined , then transform\_n\_nonzero\_coefs=int(n\_features / 10) . |
Returns
Defined in: generated/decomposition/SparseCoder.ts:25 (opens in a new tab)
Methods
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/decomposition/SparseCoder.ts:148 (opens in a new tab)
fit()
Do nothing and return the estimator unchanged.
This method is just there to implement the usual API and hence work in pipelines.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | any | Not used, present for API consistency by convention. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<any
>
Defined in: generated/decomposition/SparseCoder.ts:167 (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/decomposition/SparseCoder.ts:207 (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/decomposition/SparseCoder.ts:256 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/decomposition/SparseCoder.ts:294 (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/decomposition/SparseCoder.ts:96 (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/decomposition/SparseCoder.ts:331 (opens in a new tab)
transform()
Encode the data as a sparse combination of the dictionary atoms.
Coding method is determined by the object parameter transform\_algorithm
.
Signature
transform(opts: object): Promise<ArrayLike[]>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Training vector, where n\_samples is the number of samples and n\_features is the number of features. |
opts.y? | any | Not used, present for API consistency by convention. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/decomposition/SparseCoder.ts:366 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/decomposition/SparseCoder.ts:23 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/decomposition/SparseCoder.ts:22 (opens in a new tab)
_py
PythonBridge
Defined in: generated/decomposition/SparseCoder.ts:21 (opens in a new tab)
id
string
Defined in: generated/decomposition/SparseCoder.ts:18 (opens in a new tab)
opts
any
Defined in: generated/decomposition/SparseCoder.ts:19 (opens in a new tab)
Accessors
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/decomposition/SparseCoder.ts:404 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/decomposition/SparseCoder.ts:83 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/decomposition/SparseCoder.ts:87 (opens in a new tab)