在
x,y
中传递 fit
时,出现以下错误:
回溯(最近一次调用最后一次):
文件“C:/Classify/classifier.py”,第 95 行,位于
train_avg,test_avg,cms = train_model(X,y,“ceps”,plot = True)
文件“C:/Classify/classifier.py”,第 47 行,train_modelclf.fit(X_train, y_train) 文件“C:\Python27\lib\site-packages\sklearn\svm ase.py”,第 676 行,适合 raise ValueError("类的数量必须大于" ValueError: 类的数量必须大于 1。
下面是我的代码:
def train_model(X, Y, name, plot=False):
"""
train_model(vector, vector, name[, plot=False])
Trains and saves model to disk.
"""
labels = np.unique(Y)
cv = ShuffleSplit(n=len(X), n_iter=1, test_size=0.3, indices=True, random_state=0)
train_errors = []
test_errors = []
scores = []
pr_scores = defaultdict(list)
precisions, recalls, thresholds = defaultdict(list), defaultdict(list), defaultdict(list)
roc_scores = defaultdict(list)
tprs = defaultdict(list)
fprs = defaultdict(list)
clfs = [] # for the median
cms = []
for train, test in cv:
X_train, y_train = X[train], Y[train]
X_test, y_test = X[test], Y[test]
clf = LogisticRegression()
clf.fit(X_train, y_train)
clfs.append(clf)