Class: KernelDensity

Kernel Density Estimation.

Read more in the User Guide.

Python Reference

Constructors

new KernelDensity()

new KernelDensity(opts?): KernelDensity

Parameters

ParameterTypeDescription
opts?object-
opts.algorithm?"auto" | "ball_tree" | "kd_tree"The tree algorithm to use.
opts.atol?numberThe desired absolute tolerance of the result. A larger tolerance will generally lead to faster execution.
opts.bandwidth?number | "scott" | "silverman"The bandwidth of the kernel. If bandwidth is a float, it defines the bandwidth of the kernel. If bandwidth is a string, one of the estimation methods is implemented.
opts.breadth_first?booleanIf true (default), use a breadth-first approach to the problem. Otherwise use a depth-first approach.
opts.kernel?"linear" | "cosine" | "exponential" | "gaussian" | "tophat" | "epanechnikov"The kernel to use.
opts.leaf_size?numberSpecify the leaf size of the underlying tree. See BallTree or KDTree for details.
opts.metric?stringMetric to use for distance computation. See the documentation of scipy.spatial.distance and the metrics listed in distance_metrics for valid metric values. Not all metrics are valid with all algorithms: refer to the documentation of BallTree and KDTree. Note that the normalization of the density output is correct only for the Euclidean distance metric.
opts.metric_params?anyAdditional parameters to be passed to the tree for use with the metric. For more information, see the documentation of BallTree or KDTree.
opts.rtol?numberThe desired relative tolerance of the result. A larger tolerance will generally lead to faster execution.

Returns KernelDensity

Defined in generated/neighbors/KernelDensity.ts:23

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/neighbors/KernelDensity.ts:21
_isInitializedbooleanfalsegenerated/neighbors/KernelDensity.ts:20
_pyPythonBridgeundefinedgenerated/neighbors/KernelDensity.ts:19
idstringundefinedgenerated/neighbors/KernelDensity.ts:16
optsanyundefinedgenerated/neighbors/KernelDensity.ts:17

Accessors

bandwidth_

Get Signature

get bandwidth_(): Promise<number>

Value of the bandwidth, given directly by the bandwidth parameter or estimated using the ‘scott’ or ‘silverman’ method.

Returns Promise<number>

Defined in generated/neighbors/KernelDensity.ts:463


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/neighbors/KernelDensity.ts:438


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/neighbors/KernelDensity.ts:390


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/neighbors/KernelDensity.ts:97


tree_

Get Signature

get tree_(): Promise<any>

The tree algorithm for fast generalized N-point problems.

Returns Promise<any>

Defined in generated/neighbors/KernelDensity.ts:415

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/neighbors/KernelDensity.ts:149


fit()

fit(opts): Promise<any>

Fit the Kernel Density model on the data.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeList of sample weights attached to the data X.
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.
opts.y?anyIgnored. This parameter exists only for compatibility with Pipeline.

Returns Promise<any>

Defined in generated/neighbors/KernelDensity.ts:166


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/neighbors/KernelDensity.ts:210


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/neighbors/KernelDensity.ts:110


sample()

sample(opts): Promise<ArrayLike[]>

Generate random samples from the model.

Currently, this is implemented only for gaussian and tophat kernels.

Parameters

ParameterTypeDescription
optsobject-
opts.n_samples?numberNumber of samples to generate.
opts.random_state?numberDetermines random number generation used to generate random samples. Pass an int for reproducible results across multiple function calls. See Glossary.

Returns Promise<ArrayLike[]>

Defined in generated/neighbors/KernelDensity.ts:246


score()

score(opts): Promise<number>

Compute the total log-likelihood under the model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]List of n_features-dimensional data points. Each row corresponds to a single data point.
opts.y?anyIgnored. This parameter exists only for compatibility with Pipeline.

Returns Promise<number>

Defined in generated/neighbors/KernelDensity.ts:285


score_samples()

score_samples(opts): Promise<ArrayLike>

Compute the log-likelihood of each sample under the model.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]An array of points to query. Last dimension should match dimension of training data (n_features).

Returns Promise<ArrayLike>

Defined in generated/neighbors/KernelDensity.ts:322


set_fit_request()

set_fit_request(opts): Promise<any>

Request metadata passed to the fit 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

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/neighbors/KernelDensity.ts:358