import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import cross_val_score
#print(RFC_.fit(X,y).feature_importances_)#观察特征重要性
threshold = np.linspace(0,(RFC_.fit(X,y).feature_importances_).max(),20)#np.linspace参数分别为开头结尾选取个数,调整选取个数可以调整适合的x轴的值
print(threshold)
score = []
for i in threshold:
X_embedded = SelectFromModel(RFC_,threshold=i).fit_transform(X,y)
once = cross_val_score(RFC_,X_embedded,y,cv=5).mean()
score.append(once)
plt.plot(threshold,score)
plt.show()
threshold应该是[0. 0.00067177 0.00134354 0.00201531 0.00268707 0.00335884
0.00403061 0.00470238 0.00537415 0.00604592 0.00671769 0.00738945
0.00806122 0.00873299 0.00940476 0.01007653 0.0107483 0.01142007
0.01209183 0.0127636 ]
但是图像是这样的