DocumentationClassesLatentDirichletAllocation

Class: LatentDirichletAllocation

Latent Dirichlet Allocation with online variational Bayes algorithm.

The implementation is based on [1] and [2].

Python Reference

Constructors

new LatentDirichletAllocation()

new LatentDirichletAllocation(opts?): LatentDirichletAllocation

Parameters

ParameterTypeDescription
opts?object-
opts.batch_size?numberNumber of documents to use in each EM iteration. Only used in online learning.
opts.doc_topic_prior?numberPrior of document topic distribution theta. If the value is undefined, defaults to 1 / n_components. In [1], this is called alpha.
opts.evaluate_every?numberHow 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?numberIt 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?numberA (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?numberMax number of iterations for updating document topic distribution in the E-step.
opts.max_iter?numberThe 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?numberStopping tolerance for updating document topic distribution in E-step.
opts.n_components?numberNumber of topics.
opts.n_jobs?numberThe 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?numberPerplexity tolerance. Only used when evaluate_every is greater than 0.
opts.random_state?numberPass an int for reproducible results across multiple function calls. See Glossary.
opts.topic_word_prior?numberPrior of topic word distribution beta. If the value is undefined, defaults to 1 / n_components. In [1], this is called eta.
opts.total_samples?numberTotal number of documents. Only used in the partial_fit method.
opts.verbose?numberVerbosity level.

Returns LatentDirichletAllocation

Defined in generated/decomposition/LatentDirichletAllocation.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/decomposition/LatentDirichletAllocation.ts:21
_isInitializedbooleanfalsegenerated/decomposition/LatentDirichletAllocation.ts:20
_pyPythonBridgeundefinedgenerated/decomposition/LatentDirichletAllocation.ts:19
idstringundefinedgenerated/decomposition/LatentDirichletAllocation.ts:16
optsanyundefinedgenerated/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

ParameterType
pythonBridgePythonBridge

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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeDocument word matrix.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget 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

ParameterTypeDescription
optsobject-
opts.input_features?anyOnly 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

ParameterTypeDescription
optsobject-
opts.routing?anyA 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

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/decomposition/LatentDirichletAllocation.ts:147


partial_fit()

partial_fit(opts): Promise<any>

Online VB with Mini-Batch update.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeDocument word matrix.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
opts.sub_sampling?booleanDo sub-sampling or not.
opts.X?ArrayLikeDocument word matrix.

Returns Promise<number>

Defined in generated/decomposition/LatentDirichletAllocation.ts:415


score()

score(opts): Promise<number>

Calculate approximate log-likelihood as score.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeDocument word matrix.
opts.y?anyNot 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

ParameterTypeDescription
optsobject-
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

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeDocument word matrix.

Returns Promise<ArrayLike[]>

Defined in generated/decomposition/LatentDirichletAllocation.ts:535