sklearn是否支持动态数据的特征选择?

问题描述 投票:0回答:1

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

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

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

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

我发现了一些关于IEEE(用于特征选择的增量方法)的方法,那么sklearn或其他开放源代码库有任何实现吗?

machine-learning scikit-learn data-science feature-selection dynamic-data
1个回答
0
投票

您难道不只是按计划重新运行流程并动态加载数据吗?我完全不希望因变量发生变化,但是我想自变量可能会有所变化。

#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()

我刚刚尝试过,并且得到了这个结果。

enter image description here

如果希望获得非数字功能,则需要使用一种热编码来处理这些功能。

import pandas as pd
pd.get_dummies(df)

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

© www.soinside.com 2019 - 2024. All rights reserved.