降低分类模型过拟合度的特征选择方法[封闭式]。

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

我的数据集有200多个变量,我在上面运行一个分类模型,导致模型OverFit。有哪些建议可以减少特征的数量?我从特征重要性开始,然而由于变量数量太多,我无法将其可视化。有没有一种方法可以让我绘制或展示这些值与给定变量的关系?

以下是正在尝试的代码。

F_Select = ExtraTreesClassifier(n_estimators=50)
F_Select.fit(X_train,y_train)
print(F_Select.feature_importances_)
python machine-learning classification random-forest feature-selection
1个回答
0
投票

你可以尝试从最大到最小绘制特征进口量,看看哪些特征捕获了一定量(比如95%)的方差,就像PCA中使用的scree图一样。理想情况下,这应该是少量的特征。

import matplotlib.pyplot as plt
from sklearn import *
model = ensemble.RandomForestClassifier()
model.fit(features, labels)
model.feature_importances_
importances = np.sort(model.feature_importances_)[::-1]
cumsum = np.cumsum(importances)
plt.bar(range(len(importances)), importances)
plt.plot(cumsum)
© www.soinside.com 2019 - 2024. All rights reserved.