未知标签类型sklearn [英] Unknown label type sklearn
本文介绍了未知标签类型sklearn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是sklearn的新手.我正在尝试执行此代码
I 'm new in sklearn. I 'm trying to do this code
data = pandas.read_csv('titanic.csv')
data= data[data['Pclass'].notnull() & data['Sex'].notnull() & data['Age'].notnull() & data['Fare'].notnull()]
test = data.loc[:,['Pclass','Sex','Age','Fare']]
target = data.loc[:,['Survived']]
test = test.replace(to_replace=['male','female'],value=[1,0])
clf=DecisionTreeClassifier(random_state=241)
clf.fit(target,test)
我看到了这个错误
ValueError: Unknown label type: array([[ 22. , 3. , 7.25 , 1. ],
[ 38. , 1. , 71.2833, 0. ],
[ 26. , 3. , 7.925 , 0. ],
...,
[ 19. , 1. , 30. , 0. ],
[ 26. , 1. , 30. , 1. ],
[ 32. , 3. , 7.75 , 1. ]])
出什么问题了?
推荐答案
您当前正在提供一个数据框,而不是它的numpy数组表示形式,作为对fit
方法的训练输入.改为执行此操作:
You are currently providing a dataframe and not it's numpy array representation as the training input to the fit
method. Do this instead:
clf.fit(X=test.values, y=target.values)
# Even .asmatrix() works but is not generally recommended
这篇关于未知标签类型sklearn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文