Class: LatentDirichletAllocation
Latent Dirichlet Allocation with online variational Bayes algorithm.
The implementation is based on [1] and [2].
Constructors
new LatentDirichletAllocation()
new LatentDirichletAllocation(
opts
?):LatentDirichletAllocation
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.batch_size ? | number | Number of documents to use in each EM iteration. Only used in online learning. |
opts.doc_topic_prior ? | number | Prior of document topic distribution theta . If the value is undefined , defaults to 1 / n_components . In [1], this is called alpha . |
opts.evaluate_every ? | number | How often to evaluate perplexity. Only used in fit method. set it to 0 or negative number to not evaluate perplexity in training at all. Evaluating perplexity can help you check convergence in training process, but it will also increase total training time. Evaluating perplexity in every iteration might increase training time up to two-fold. |
opts.learning_decay ? | number | It is a parameter that control learning rate in the online learning method. The value should be set between (0.5, 1.0] to guarantee asymptotic convergence. When the value is 0.0 and batch_size is n_samples , the update method is same as batch learning. In the literature, this is called kappa. |
opts.learning_method ? | "batch" | "online" | Method used to update _component . Only used in fit method. In general, if the data size is large, the online update will be much faster than the batch update. Valid options: |
opts.learning_offset ? | number | A (positive) parameter that downweights early iterations in online learning. It should be greater than 1.0. In the literature, this is called tau_0. |
opts.max_doc_update_iter ? | number | Max number of iterations for updating document topic distribution in the E-step. |
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. |
opts.mean_change_tol ? | number | Stopping tolerance for updating document topic distribution in E-step. |
opts.n_components ? | number | Number of topics. |
opts.n_jobs ? | number | The number of jobs to use in the E-step. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details. |
opts.perp_tol ? | number | Perplexity tolerance. Only used when evaluate_every is greater than 0. |
opts.random_state ? | number | Pass an int for reproducible results across multiple function calls. See Glossary. |
opts.topic_word_prior ? | number | Prior of topic word distribution beta . If the value is undefined , defaults to 1 / n_components . In [1], this is called eta . |
opts.total_samples ? | number | Total number of documents. Only used in the partial_fit method. |
opts.verbose ? | number | Verbosity level. |
Returns LatentDirichletAllocation
Defined in generated/decomposition/LatentDirichletAllocation.ts:23
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/decomposition/LatentDirichletAllocation.ts:21 |
_isInitialized | boolean | false | generated/decomposition/LatentDirichletAllocation.ts:20 |
_py | PythonBridge | undefined | generated/decomposition/LatentDirichletAllocation.ts:19 |
id | string | undefined | generated/decomposition/LatentDirichletAllocation.ts:16 |
opts | any | undefined | generated/decomposition/LatentDirichletAllocation.ts:17 |
Accessors
bound_
Get Signature
get bound_():
Promise
<number
>
Final perplexity score on training set.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:733
components_
Get Signature
get components_():
Promise
<ArrayLike
[]>
Variational parameters for topic word distribution. Since the complete conditional for topic word distribution is a Dirichlet, components_\[i, j\]
can be viewed as pseudocount that represents the number of times word j
was assigned to topic i
. It can also be viewed as distribution over the words for each topic after normalization: model.components_ / model.components_.sum(axis=1)\[:, np.newaxis\]
.
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/LatentDirichletAllocation.ts:571
doc_topic_prior_
Get Signature
get doc_topic_prior_():
Promise
<number
>
Prior of document topic distribution theta
. If the value is undefined
, it is 1 / n_components
.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:760
exp_dirichlet_component_
Get Signature
get exp_dirichlet_component_():
Promise
<ArrayLike
[]>
Exponential value of expectation of log topic word distribution. In the literature, this is exp(E\[log(beta)\])
.
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/LatentDirichletAllocation.ts:598
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/decomposition/LatentDirichletAllocation.ts:679
n_batch_iter_
Get Signature
get n_batch_iter_():
Promise
<number
>
Number of iterations of the EM step.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:625
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:652
n_iter_
Get Signature
get n_iter_():
Promise
<number
>
Number of passes over the dataset.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:706
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/decomposition/LatentDirichletAllocation.ts:134
random_state_
Get Signature
get random_state_():
Promise
<any
>
RandomState instance that is generated either from a seed, the random number generator or by np.random
.
Returns Promise
<any
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:787
topic_word_prior_
Get Signature
get topic_word_prior_():
Promise
<number
>
Prior of topic word distribution beta
. If the value is undefined
, it is 1 / n_components
.
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:814
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/decomposition/LatentDirichletAllocation.ts:190
fit()
fit(
opts
):Promise
<any
>
Learn model for the data X with variational Bayes method.
When learning_method
is ‘online’, use mini-batch update. Otherwise, use batch update.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Document word matrix. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:209
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/decomposition/LatentDirichletAllocation.ts:250
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/decomposition/LatentDirichletAllocation.ts:298
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/decomposition/LatentDirichletAllocation.ts:336
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/decomposition/LatentDirichletAllocation.ts:147
partial_fit()
partial_fit(
opts
):Promise
<any
>
Online VB with Mini-Batch update.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Document word matrix. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:372
perplexity()
perplexity(
opts
):Promise
<number
>
Calculate approximate perplexity for data X.
Perplexity is defined as exp(-1. * log-likelihood per word)
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sub_sampling ? | boolean | Do sub-sampling or not. |
opts.X ? | ArrayLike | Document word matrix. |
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:415
score()
score(
opts
):Promise
<number
>
Calculate approximate log-likelihood as score.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Document word matrix. |
opts.y ? | any | Not used, present here for API consistency by convention. |
Returns Promise
<number
>
Defined in generated/decomposition/LatentDirichletAllocation.ts:456
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/decomposition/LatentDirichletAllocation.ts:499
transform()
transform(
opts
):Promise
<ArrayLike
[]>
Transform data X according to the fitted model.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | Document word matrix. |
Returns Promise
<ArrayLike
[]>
Defined in generated/decomposition/LatentDirichletAllocation.ts:535