我有以下值:
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
d = {'Pos': [1,2,3,4,5,6,7,8,9,10], 'Neg': [10,9,8,7,6,5,4,3,2,1], 'Res': ['win','win','win','win','draw','loss','loss','loss','loss','loss',]}
df = pd.DataFrame(d)
然后我尝试实现以下简单的朴素贝叶斯分类
train, test = train_test_split(df,test_size=0.2)
train_data = (train.Pos.values, train.Neg.values)
train_target = train.Res.values
model.fit(train_data, train_target)
但是我不断收到以下错误:
Found input variables with inconsistent numbers of samples: [2, 8]
我已经试验过了,似乎不是读取两个数组的值,而是读取多少个数组(train.Pos.values,train.Neg.Values);这可能会导致问题。
为什么会这样?我该如何修改我的代码来解决这个问题?
使用
train, test = train_test_split(df,test_size=0.2)
train_data = train[['Pos', 'Neg']]
train_target = train['Res']
我是一名优秀的程序员,十分优秀!