我如何更改功能重要性,使其不再是随机的?在Python中
我正在使用基于决策树的特征重要性进行特征选择。
#Feature importance (source: https://towardsdatascience.com/feature-selection-techniques-in-machine-learning-with-python-f24e7da3f36e)
X = df.iloc[:,1:31] #independent columns
y = df.iloc[:,0] #target column = diagnosis
model = ExtraTreesClassifier()
model.fit(X,y)
print(model.feature_importances_) #use inbuilt class feature_importances of tree based classifiers
feat_importances = pd.Series(model.feature_importances_, index=X.columns)
feat_importances.nlargest(10).plot(kind='barh', color="lightskyblue")
plt.show()
但每次我再次启动时结果都会改变,可能某个地方有一个随机数。有没有办法设置一次然后保持不变,以便每次重新启动内核时结果都不会改变?
谢谢。
更新:我想我使用以下方法来管理它: 模型 = ExtraTreesClassifier(random_state=1) 这是正确的做法吗?
I am doing feature selection using feature importance which is based on a decision tree.
#Feature importance (source: https://towardsdatascience.com/feature-selection-techniques-in-machine-learning-with-python-f24e7da3f36e)
X = df.iloc[:,1:31] #independent columns
y = df.iloc[:,0] #target column = diagnosis
model = ExtraTreesClassifier()
model.fit(X,y)
print(model.feature_importances_) #use inbuilt class feature_importances of tree based classifiers
feat_importances = pd.Series(model.feature_importances_, index=X.columns)
feat_importances.nlargest(10).plot(kind='barh', color="lightskyblue")
plt.show()
But the results change everytime i start it again, probably somewhere there is a random number somewhere. Is there a way to set this once and then keep it the same so that the results don't change everytime the kernel is restarted?
Thank you.
UPDATE: I think I managed it using:
model = ExtraTreesClassifier(random_state=1)
is that the right way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
ExtraTreesClassifier
的random_state
参数设置为某个值。在这种情况下,您将获得可重复的结果。例如:
You can set a
random_state
parameter ofExtraTreesClassifier
to some value. In this case you will get reproducible results.For example: