Documentation
Classes
KernelDensity

KernelDensity

Kernel Density Estimation.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new KernelDensity(opts?: object): KernelDensity;

Parameters

NameTypeDescription
opts?object-
opts.algorithm?"auto" | "ball_tree" | "kd_tree"The tree algorithm to use. Default Value 'auto'
opts.atol?numberThe desired absolute tolerance of the result. A larger tolerance will generally lead to faster execution. Default Value 0
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. Default Value 1
opts.breadth_first?booleanIf true (default), use a breadth-first approach to the problem. Otherwise use a depth-first approach. Default Value true
opts.kernel?"linear" | "cosine" | "exponential" | "gaussian" | "tophat" | "epanechnikov"The kernel to use. Default Value 'gaussian'
opts.leaf_size?numberSpecify the leaf size of the underlying tree. See BallTree or KDTree for details. Default Value 40
opts.metric?stringMetric to use for distance computation. See the documentation of scipy.spatial.distance (opens in a new tab) 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. Default Value 'euclidean'
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. Default Value 0

Returns

KernelDensity

Defined in: generated/neighbors/KernelDensity.ts:23 (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/neighbors/KernelDensity.ts:158 (opens in a new tab)

fit()

Fit the Kernel Density model on the data.

Signature

fit(opts: object): Promise<any>;

Parameters

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

Returns

Promise<any>

Defined in: generated/neighbors/KernelDensity.ts:175 (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

NameTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns

Promise<any>

Defined in: generated/neighbors/KernelDensity.ts:224 (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

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/neighbors/KernelDensity.ts:110 (opens in a new tab)

sample()

Generate random samples from the model.

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

Signature

sample(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.n_samples?numberNumber of samples to generate. Default Value 1
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:261 (opens in a new tab)

score()

Compute the total log-likelihood under the model.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
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:301 (opens in a new tab)

score_samples()

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

Signature

score_samples(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
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:339 (opens in a new tab)

set_fit_request()

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:

Signature

set_fit_request(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in fit.

Returns

Promise<any>

Defined in: generated/neighbors/KernelDensity.ts:376 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/neighbors/KernelDensity.ts:21 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/neighbors/KernelDensity.ts:20 (opens in a new tab)

_py

PythonBridge

Defined in: generated/neighbors/KernelDensity.ts:19 (opens in a new tab)

id

string

Defined in: generated/neighbors/KernelDensity.ts:16 (opens in a new tab)

opts

any

Defined in: generated/neighbors/KernelDensity.ts:17 (opens in a new tab)

Accessors

bandwidth_

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

Signature

bandwidth_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/neighbors/KernelDensity.ts:482 (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/neighbors/KernelDensity.ts:457 (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/neighbors/KernelDensity.ts:409 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/neighbors/KernelDensity.ts:97 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/neighbors/KernelDensity.ts:101 (opens in a new tab)

tree_

The tree algorithm for fast generalized N-point problems.

Signature

tree_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/neighbors/KernelDensity.ts:434 (opens in a new tab)