Answers for "how to remove outliers in machine learning"

2

delete outliers in pandas

cols = ['col_1', 'col_2'] # one or more

Q1 = df[cols].quantile(0.25)
Q3 = df[cols].quantile(0.75)
IQR = Q3 - Q1

df = df[~((df[cols] < (Q1 - 1.5 * IQR)) |(df[cols] > (Q3 + 1.5 * IQR))).any(axis=1)]
Posted by: Guest on December-02-2020
0

outliers removal

#Removing outliers first then skewness
from scipy.stats import zscore
z=abs(zscore(df))
print(z.shape)
df=df[(z<3).all(axis=1)]
df.shape
Posted by: Guest on August-11-2020

Code answers related to "how to remove outliers in machine learning"

Python Answers by Framework

Browse Popular Code Answers by Language