FRE 和 随机森林 特征重要性

#使用ref进行特征选择
from sklearn.linear_model import LinearRegression, Ridge
from sklearn import svm
from sklearn.feature_selection import RFE
lr = LinearRegression()
rfe = RFE(lr, n_features_to_select=5)
rfe.fit(train_X,label_1)
print ("Features sorted by their rank:")
print( sorted(zip(map(lambda x: round(x, 4), rfe.ranking_), feature))  )



#使用随机森林进行特征选择
from sklearn.ensemble import RandomForestRegressor
import numpy as np
rf = RandomForestRegressor()
rf.fit(train_X,label_1)
print ("Features sorted by their score:")
print (sorted(zip(map(lambda x: round(x, 4), rf.feature_importances_), feature),
             reverse=True))

你可能感兴趣的:(ᕦ,机器学习,ᕤ,1024程序员节,随机森林,特征,RFE)