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
vDataColumnlabeled with 0 or 1, where 1 indicates that the record is a global outlier.Parameters¶
- columns: SQLColumns, optional
List of the
vDataColumnnames. If empty, all numericalvDataColumnare 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 fromverticapyare used as intended without interfering with functions from other libraries.Let us create a
vDataFramethat 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})
123vals100%1 1.1126219312929608 2 -1.7770956921599177 3 1.307619870179214 4 -0.019102765434878145 5 -0.5229321981867747 6 1.909432406454482 7 -0.9220622606221466 8 -2.361790886312269 9 0.8469442641498722 10 -0.459304171000335 11 100.0 Now we can see which values are outliers by using the
vDataFrame.outliers()method:vdf.outliers()
123vals100%123distribution_outliers100%1 1.1126219312929608 0 2 -1.7770956921599177 0 3 1.307619870179214 0 4 -0.019102765434878145 0 5 -0.5229321981867747 0 6 1.909432406454482 0 7 -0.9220622606221466 0 8 -2.361790886312269 0 9 0.8469442641498722 0 10 -0.459304171000335 0 11 100.0 1 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.