Loading...

verticapy.vDataFrame.outliers

vDataFrame.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) → vDataFrame

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

Parameters

columns: SQLColumns, optional

List of the vDataColumn names. If empty, all numerical vDataColumn are used.

name: str, optional

Name of the new vDataColumn.

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

vDataFrame

self

Examples

Let’s begin by importing VerticaPy.

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy 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 verticapy are used as intended without interfering with functions from other libraries.

Let us create a vDataFrame that has some outliers:

import numpy as np

data = np.random.normal(
    loc = 0,
    scale = 1,
    size = 10,
)


data = np.append(data, [100])

vdf = vp.vDataFrame({"vals": data})
123
vals
Numeric(22)
100%
10.15966826598891262
2-0.7392875587393709
31.3675576813448003
40.37328182776591784
50.730868478850289
6-0.5013881702117058
7-0.16832406915379716
81.085607214263689
90.5027526460644856
100.4386807845747028
11100.0

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

vdf.outliers()
123
vals
Numeric(22)
100%
123
distribution_outliers
Integer
100%
10.159668265988912620
2-0.73928755873937090
31.36755768134480030
40.373281827765917840
50.7308684788502890
6-0.50138817021170580
7-0.168324069153797160
81.0856072142636890
90.50275264606448560
100.43868078457470280
11100.01

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

vDataFrame.outliers_plot() : Plots the outliers.