import numpy
as np
from sklearn
.feature_selection
import RFE
, RFECV
from sklearn
.svm
import SVC
, SVR
from sklearn
.svm
import LinearSVC
from sklearn
import model_selection
import pandas
as pd
df
= pd
.read_csv
('E:\Pycharm\PycharmLearning\RF\\RFEtestyu1012.csv', encoding
='gbk')
print(df
.head
())
df
.label
=df
.label
.astype
(str)
y
=df
.label
print(y
.head
())
x
=df
.drop
('label', axis
=1)
print(x
.head
())
features
= x
print('开始训练特征')
svc
= SVC
(kernel
="linear", C
=1)
rfe
= RFE
(estimator
=svc
, n_features_to_select
=1, step
=1)
rfe
.fit
(x
,y
)
print('训练特征选择完成,输出特征:')
result
= features
.columns
[rfe
.get_support
()]
print(result
)
print(rfe
.ranking_
)
estimator1
= SVR
(kernel
='linear')
re
= RFECV
(estimator
=estimator1
, step
=1, cv
=10)
re
.fit
(x
,y
)
print('特征输出完毕')
转载请注明原文地址: https://lol.8miu.com/read-15240.html