【问题标题】:How do I pre-process the dataset if the feature ranges are too wide?如果特征范围太宽,如何预处理数据集?
【发布时间】:2020-07-13 21:13:18
【问题描述】:

我有一个包含 5 个特征的数据集,每列的数字范围不同。我尝试过使用 MinMaxScaler 和 StandardScaler,但是这个多类问题的准确率太低了。

【问题讨论】:

    标签: data-science


    【解决方案1】:

    如果 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

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-08
      相关资源
      最近更新 更多