飞翔鸟

人生无止境,奋斗不息

valueError: This solver needs samples of at least 2 classes in the data, but the data contains only one class: 0

问题描述:执行下面的代码,报错valueError: This solver needs samples of at least 2 classes in the data, but the data contains only one class: 0

原因:数据量太少

解决方案:增加训练数据量

代码如下:

filename = "test.csv"
data = pd.read_csv(filename,sep=' ')
data = pd.DataFrame(data)

x = data.iloc[:,:8].as_matrix()
y = data.iloc[:,8].as_matrix()


from sklearn.linear_model import LogisticRegression as LR
from sklearn.linear_model import RandomizedLogisticRegression as RLR
rlr = RLR() # 建立随机逻辑回归模型,筛选变量
rlr.fit(x, y)
rlr.get_support()
print (rlr.get_support())
print ("*********************88")
print (u'有效特征:%s' % ','.join(data.columns[rlr.get_support()]))

  

 

posted @ 2018-04-08 16:34  飞翔—鸟  阅读(5037)  评论(0编辑  收藏  举报