KernelDensity
- class sklearn.neighbors.KernelDensity(*, bandwidth=1.0, algorithm='auto', kernel='gaussian', metric='euclidean', atol=0, rtol=, , ,
Kernel Density Estimation.
Read more in the User Guide.
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.
The tree algorithm to use.
The kernel to use.
Metric 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.
The desired absolute tolerance of the result. A larger tolerance will generally lead to faster execution.
The desired relative tolerance of the result. A larger tolerance will generally lead to faster execution.
If true (default), use a breadth-first approach to the problem. Otherwise use a depth-first approach.
Specify the leaf size of the underlying tree. See BallTree
or KDTree for details.
Additional parameters to be passed to the tree for use with the
metric. For more information, see the documentation of
BallTree or KDTree.
Compute a gaussian kernel density estimate with a fixed bandwidth.
>>> from sklearn.neighbors import KernelDensity
>>> import numpy as np
>>> rng = np.random.RandomState(42)
>>> X = rng.random_sample((100, 3))
>>>
Fit the Kernel Density model on the data.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Generate random samples from the model.
Currently, this is implemented only for gaussian and tophat kernels.
Compute the total log-likelihood under the model.
List of n_features-dimensional data points. Each row corresponds to a single data point.
Ignored. This parameter exists only for compatibility with
Pipeline.
Compute the log-likelihood of each sample under the model.
An array of points to query. Last dimension should match dimension of training data (n_features).
Log-likelihood of each sample in X. These are normalized to be
probability densities, so values will be low for high-dimensional
data.
Configure whether metadata should be requested to be passed to the method.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Estimator parameters.
XValue of the bandwidth, given directly by the bandwidth parameter or estimated using the ‘scott’ or ‘silverman’ method.
PipelineList of sample weights attached to the data X.
Returns the instance itself.
List of samples.
Total log-likelihood of the data in X. This is normalized to be a probability density, so the value will be low for high-dimensional data.
Note that this method is only relevant when this estimator is used as a
sub-estimator within a meta-estimator and metadata routing is enabled
with enable_metadata_routing=True (see sklearn.set_config).
Please check the User Guide on how the routing
mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to fit.
None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED) retains the
existing request. This allows you to change the request for some
parameters and not others.
Metadata routing for sample_weight parameter in fit.
The updated object.
Estimator instance.