【发布时间】:2016-09-26 09:03:40
【问题描述】:
我试图按照给定的教程here 使用我自己的数据使用 scikit-learn 的递归特征消除和交叉验证 (RFECV) 功能,并不断遇到令人费解的错误:
ValueError: 找到包含 0 个样本 (shape=(0, 9)) 的数组,而至少需要 1 个。
我使用的代码如下:
import pandas as pd
import numpy as np
from sklearn import svm
from sklearn.cross_validation import StratifiedKFold
from sklearn.feature_selection import RFECV
data = pd.read_csv('data.csv', index_col = 0)
training = data.iloc[:50]
# training on the first 50 rows
training_y = np.asarray(training.C1, dtype="|S6")
training_x = training.drop('C1', axis=1)
print training_y.shape
print training_x.shape
# Create the RFE object and compute a cross-validated score.
svc = svm.SVC(kernel="linear")
# The "accuracy" scoring is proportional to the number of correct
# classifications
rfecv = RFECV(estimator = svc, step = 1, cv = StratifiedKFold(training_y, 3),
scoring = 'accuracy')
rfecv.fit(training_x, training_y)
仅供参考,两条打印语句的输出为:
(50,)
(50, 9)
谢谢!
【问题讨论】:
标签: python scikit-learn