【问题标题】:How to resolve ValueError: The number of classes has to be greater than one; got 1 class如何解决ValueError:类的数量必须大于1;上了一堂课
【发布时间】:2021-07-22 05:36:13
【问题描述】:

当我运行以下内容时:

from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
clf=SVC(kernel='rbf',probability=True)
clf.fit(x_train,y_train)

我收到了 ValueError:The number of classes has to be greater than one; got 1 class 我使用了代码:print(np.unique(y_train)),它返回“[0]”。 谁能指出我正确的解决方案?

【问题讨论】:

    标签: python svc


    【解决方案1】:

    要么您的y 列表不包含 1,要么 y 中的 1 太少以至于 y_train 最终可能不包含 1。你应该打印y,如果它包含1,你需要改变你的拆分策略,以确保所有类都存在于y_trainy_test中至少一次

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 2017-04-08
      • 2021-12-10
      • 2019-02-18
      • 2017-10-29
      • 2017-04-10
      相关资源
      最近更新 更多