我受不了了 rfecv拿过来做特征筛选 放的是svm linear就可以用 换成rbf就报错
f"when importance_getter=='auto'
, the underlying "
ValueError: when importance_getter=='auto'
, the underlying estimator SVC should have coef_
or feature_importances_
attribute. Either pass a fitted estimator to feature selector or call fit before calling transform.
我的问题第一个是为什么会出现这种情况
第二个问题是importance——getter有几种参数
第三个问题是svc好像没有coef——和feature——importances
Python代码
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
iris = datasets.load_iris()
X = iris.data
y = iris.target
X = X [y<2,:2] #只取y<2的类别,也就是0 1 并且只取前两个特征
y = y[y<2] # 只取y<2的类别
# 分别画出类别0和1的点
plt.scatter(X[y==0,0],X[y==0,1],color='red')
plt.scatter(X[y==1,0],X[y==1,1],color='blue')
plt.show()
# 标准化
standardScaler = StandardScaler()
standardScaler.fit(X) #计算训练数据的均值和方差
X_standard = standardScaler.transform(X) #再用scaler中的均值和方差来转换X,使X标准化
svc = LinearSVC(C=1e9) #线性SVM分类器
svc.fit(X_standard,y) # 训练svm
数据显示结果