Bernoulli Naive Bayes错误:ValueError:未知的标签类型:(array([0,0,0,…,0,0,0],dtype=object),)

2024-04-25 16:54:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个numpy数组x和y从一个sframe中获得,其中x有6个维度,y(目标变量)有一个维度。在

x =np.array([[ 0 , 0 , 0, 24 ,0, 34], [ 0 , 0 , 0, 22 ,0, 34], ...])
y = np.array([[0], [0], [0], [1], [1], ...])

我正在使用scikit学习应用naivebayes分类器。当我试图在naivebayes分类器中拟合x和y时,我给出了以下错误:

^{pr2}$

这是我的代码:

from sklearn.naive_bayes import BernoulliNB
naive_bayes = BernoulliNB(alpha=1e-2)
#x = self.training1[self.feature_columns].to_numpy()
#x = x.reshape(-len(self.feature_columns), len(self.feature_columns))
#y = self.training1[[target_column]].to_numpy()
#y = y.reshape(-1L,1L)    
x =np.array([[ 0 , 0 , 0, 24 ,0, 34], [ 0 , 0 , 0, 22 ,0, 34], ...])
y = np.array([[0], [0], [0], [1], [1], ...])    
naive_bayes.fit(x, y)

我哪里出错了?在


Tags: columnstoselfnumpylen分类器nparray