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(23)
100%
11.1126219312929608
2-1.7770956921599177
31.307619870179214
4-0.019102765434878145
5-0.5229321981867747
61.909432406454482
7-0.9220622606221466
8-2.361790886312269
90.8469442641498722
10-0.459304171000335
11100.0

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

vdf.outliers()
123
vals
Numeric(23)
100%
123
distribution_outliers
Integer
100%
11.11262193129296080
2-1.77709569215991770
31.3076198701792140
4-0.0191027654348781450
5-0.52293219818677470
61.9094324064544820
7-0.92206226062214660
8-2.3617908863122690
90.84694426414987220
10-0.4593041710003350
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.