SubLOF
Timeseries version of local outlier factor.
Quickstart
from sktime.detection.lof import SubLOF
estimator = SubLOF(n_neighbors, window_size, *, algorithm='auto', leaf_size=30, metric='minkowski', p=2, metric_params=None, contamination='auto', novelty=False, n_jobs=None)Parameters(10)
- n_neighborsint, default=20
Number of neighbors to use by default for
kneighborsqueries. If n_neighbors is larger than the number of samples provided, all samples will be used.- window_sizeint, float, timedelta
- Size of the non-overlapping windows on which the LOF models are fit.
- algorithm{‘auto’, ‘ball_tree’, ‘kd_tree’, ‘brute’}, default=’auto’
Algorithm used to compute the nearest neighbors:
‘ball_tree’ will use
BallTree‘kd_tree’ will use
KDTree‘brute’ will use a brute-force search.
‘auto’ will attempt to decide the most appropriate algorithm based on the values passed to
fitmethod.
Note: fitting on sparse input will override the setting of this parameter, using brute force.
- leaf_sizeint, default=30
Leaf is size passed to
BallTreeorKDTree. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.- metricstr or callable, default=’minkowski’
Metric to use for distance computation. Default is “minkowski”, which results in the standard Euclidean distance when p = 2. See the documentation of scipy.spatial.distance and the metrics listed in
distance_metricsfor valid metric values.If metric is “precomputed”, X is assumed to be a distance matrix and must be square during fit. X may be a sparse graph, in which case only “nonzero” elements may be considered neighbors.
If metric is a callable function, it takes two arrays representing 1D vectors as inputs and must return one value indicating the distance between those vectors. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string.
- pfloat, default=2
Parameter for the Minkowski metric from
sklearn.metrics.pairwise_distances. When p = 1, this is equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.- metric_paramsdict, default=None
- Additional keyword arguments for the metric function.
- contamination‘auto’ or float, default=’auto’
The amount of contamination of the data set, i.e. the proportion of outliers in the data set. When fitting this is used to define the threshold on the scores of the samples.
if ‘auto’, the threshold is determined as in the original paper,
if a float, the contamination should be in the range (0, 0.5].
Changed in version 0.22: The default value of
contaminationchanged from 0.1 to'auto'.- noveltybool, default=False
- By default, LocalOutlierFactor is only meant to be used for outlier detection (novelty=False). Set novelty to True if you want to use LocalOutlierFactor for novelty detection. In this case be aware that you should only use predict, decision_function and score_samples on new unseen data and not on the training set; and note that the results obtained this way may differ from the standard LOF results.
- n_jobsint, default=None
The number of parallel jobs to run for neighbors search.
Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means using all processors. See Glossary for more details.
Examples
>>> import pandas as pd
>>> from sktime.detection.lof import SubLOF
>>> model = SubLOF (3, window_size = 5, novelty = True)
>>> x = pd. DataFrame ([0, 0.5, 100, 0.1, 0, 0, 0, 100, 0, 0, 0.3, - 1, 0, 100, 0.2 ])
>>> model. fit_transform (x) labels 0 0 1 0 2 1 3 0 4 0 5 0 6 0 7 1 8 0 9 0 10 0 11 0 12 0 13 1 14 0