gpt4 book ai didi

python - 样本数量不一致的变量,朴素贝叶斯

转载 作者:太空宇宙 更新时间:2023-11-04 02:27:30 27 4
gpt4 key购买 nike

我有以下值:

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']

关于python - 样本数量不一致的变量,朴素贝叶斯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49988389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com