python - Python Naive Bayes 训练问题 - cannoy 使用灵活类型执行 reduce
问题描述
我的目标是训练一个贝叶斯模型来审查正面和负面的句子。我有 6000 个单词来训练模型,想用诸如“我感到很高兴”之类的句子来测试它。
我目前正在将 numpy 与 sklearn 一起使用,但遇到类型错误的问题:“无法使用灵活类型执行 reduce”。
我有一个单词列表 likewords = ["good", "happy", "bad", "sad"]
和一个相应的列表wordTypes = ["positive", "positive", "negative", "negative"]
。我试图简化它以得到一些工作,所以结果是下面的代码。我还使用了“str”而不是正负,X
以及括号而不是方括号。
from sklearn.naive_bayes import GaussianNB
import numpy as np
nv = GaussianNB()
X = [["happy","positive"], ["good","positive"], ["bad","negative"], ["poor", "negative"]]
y = ["positive","positive", "negative","negative"]
nv.fit(X,y)
我也尝试过如下,但得到以下内容:ValueError: Expected 2D array, got 1D array instead: array=['happy' 'good' 'bad' 'poor']. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
X = ["happy", "good", "bad", "poor"]
y = ["positive","positive", "negative","negative"]
我是否误解了它们的结构?
解决方案
推荐阅读
- python-3.x - Django 模型设置
- arrays - 位操作函数没有给出所需的结果
- android - 如何以编程方式从状态栏android清除firebase推送通知
- android - 为什么垂直文本视图的重力或文本对齐不起作用?
- r - 为特定值“手动”计算核密度估计
- python - Django:无法访问此站点
- html - 图片在网络中加载但不显示 Github 页面
- python - 如何在 python 中使用带有类型提示的 Flask
- date - 如何为给定日期列(具有重复日期)创建一系列时间戳?
- javascript - 未捕获的类型错误:无法通过创建图表来读取未定义的属性“名字”