【发布时间】:2020-07-13 21:13:18
【问题描述】:
【问题讨论】:
标签: data-science
【问题讨论】:
标签: data-science
如果 StandardScaler 和 MinMaxScaler 没有达到预期的效果,那么要检查的另一件事是倾斜数据:
# Check the skew of all numerical features
numeric_feats = all_data.dtypes[all_data.dtypes != "object"].index
skewed_feats = all_data[numeric_feats].apply(lambda x: skew(x.dropna())).sort_values(ascending=False)
print("\nSkew in numerical features: \n")
skewness = pd.DataFrame({'Skew' :skewed_feats})
skewness.head(10)
越低越好。如果您获得高分,您可以使用变换(log、boxcox 等)使数据分布在形状上更正常。
校正偏斜:
skewness = skewness[abs(skewness) > 0.75]
print("There are {} skewed numerical features to Box Cox transform".format(skewness.shape[0]))
from scipy.special import boxcox1p
skewed_features = skewness.index
lam_f = 0.15
for feat in skewed_features:
#all_data[feat] += 1
all_data[feat] = boxcox1p(all_data[feat], lam_f)
其他尝试:
要么删除传单,要么尝试 RobustScaler() 电源变压器()
参考:https://scikit-learn.org/stable/auto_examples/preprocessing/plot_all_scaling.html
【讨论】: