【问题标题】:Does sklearn supports feature selection on dynamic data?sklearn 是否支持动态数据的特征选择?
【发布时间】:2020-08-10 22:12:10
【问题描述】:

sklearn包含不同特征选择方法的实现(filter/wrapper/embedded).

所有为静态系统设计的方法。

sklearn 是否支持动态数据的特征选择? (随时间变化的数据)

在动态数据中,我们需要提高特征选择的效率,才能更有效。

我在 IEEE 上找到了一些方法(特征选择的增量方法), 那么sklearn 或其他开源库是否有任何实现?

【问题讨论】:

    标签: machine-learning scikit-learn data-science feature-selection dynamic-data


    【解决方案1】:

    难道您不能按计划重新运行您的流程并动态加载您的数据吗?我不认为因变量会发生变化,但我认为自变量可能会有所变化。

    #1)  load your dataframe
    #2)  copy your target variable into a new dataframe
    
    y = df[['SeriousDlqin2yrs']]
    
    #3)  drop your target variable
    
    x = df[df.columns[df.columns!='SeriousDlqin2yrs']]
    

    最后,运行这个。

    from sklearn.ensemble import RandomForestClassifier
    features = np.array(x)
    clf = RandomForestClassifier()
    clf.fit(x, y)
    # from the calculated importances, order them from most to least important
    # and make a barplot so we can visualize what is/isn't important
    importances = clf.feature_importances_
    sorted_idx = np.argsort(importances)
    padding = np.arange(len(features)) + 0.5
    plt.barh(padding, importances[sorted_idx], align='center')
    plt.yticks(padding, features[sorted_idx])
    plt.xlabel("Relative Importance")
    plt.title("Variable Importance")
    plt.show()
    

    我刚刚试了一下,得到了这个结果。

    如果您希望获得非数字特征,您将需要使用一种热编码来处理这些。

    import pandas as pd
    pd.get_dummies(df)
    

    http://queirozf.com/entries/one-hot-encoding-a-feature-on-a-pandas-dataframe-an-example

    【讨论】:

      猜你喜欢
      • 2017-04-06
      • 2014-09-21
      • 2017-04-26
      • 2016-08-04
      • 2019-01-12
      • 2014-02-27
      • 2016-05-08
      • 1970-01-01
      • 2018-02-27
      相关资源
      最近更新 更多