今天使用Python的sklearn模块训练模型时,报错ValueError: The number of classes has to be greater than one; got 1 class,如下:
clf.fit(x,y)
->ValueError: The number of classes has to be greater than one; got 1 class
最后发现是样本原因,y变量只有一个类型,如下:
y.value_counts()
->-1 263
这也是报错的原因,指的是我们的预测变量y只有一个类型。