Loading...

vastorbit.VastFrame.outliers

VastFrame.outliers(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, name: str = 'distribution_outliers', threshold: float = 3.0, robust: bool = False) VastFrame

Adds a new VastColumn labeled with 0 or 1, where 1 indicates that the record is a global outlier.

Parameters:
  • columns (SQLColumns, optional) – List of the VastColumn names. If empty, all numerical VastColumn are used.

  • name (str, optional) – Name of the new VastColumn.

  • threshold (float, optional) – Threshold equal to the critical score.

  • robust (bool) – If set to True, uses the Robust Z-Score instead of the Z-Score.

Returns:

self

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

Let us create a VastFrame that has some outliers:

import numpy as np

data = np.random.normal(
    loc = 0,
    scale = 1,
    size = 10,
)
data = np.append(data, [100])
vdf = vo.VastFrame({"vals": data})
123
vals
Decimal(19, 16)
11.0238377252508037
20.5287504688558247
3-0.1785129022533889
4-0.7494816555248112
5100.0
6-0.8238795757236385
70.847378126053947
82.2753217834369743
90.6783591155305716
100.7945278832355748
11-2.055084187529675
Rows: 1-11 | Column: vals | Type: decimal(19, 16)

Now we can see which values are outliers by using the VastFrame.outliers() method:

vdf.outliers()
123
vals
Decimal(19, 16)
123
distribution_outliers
Integer
10.79452788323557480
2-0.82387957572363850
3-0.74948165552481120
41.02383772525080370
50.52875046885582470
6100.01
7-0.17851290225338890
80.8473781260539470
90.67835911553057160
102.27532178343697430
11-2.0550841875296750
Rows: 1-11 | Columns: 2

Note

This function can only identify global outliers in the distribution. For other types of outliers, it is recommended to create machine learning models.

See also

VastFrame.outliers_plot() : Plots the outliers.