【问题标题】:How to predict dataset using NaiveBayes如何使用 NaiveBayes 预测数据集
【发布时间】:2018-10-31 22:08:08
【问题描述】:
x=dataset1[:,1:23] # features
y=dataset1[:,0] #classtypes 
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.20)

我的数据集只有字母。 1 行有 23 个字母。 第一个字母是classtype,其他字母是feauters。我有 2 节课 --> a,z

示例:a,b,c,d,e,...,g

我会先计算召回率、精度和其他值。我需要找到 ypred 导致这些值询问 2 个参数(ytest,ypred) 。 如何使用朴素贝叶斯预测数据?

【问题讨论】:

  • 你使用了什么算法?来自 sklearn 的 GaussianNB?
  • 从 nltk.classify 导入 NaiveBayesClassifier 从 nltk.classify.scikitlearn 导入 SklearnClassifier 。并与 . nc = NaiveBayesClassifier.train(train1)。 Train1 是我数据集的 3/4

标签: machine-learning nltk predict naivebayes


【解决方案1】:

我建议您查看用于朴素贝叶斯分类器的 sklearn 文档:here

【讨论】:

  • 我使用了分类方法和准确度方法,但没有其他值的预测或方法(精度,f score)。首先我需要预测方法:/。我的数据不是整数或浮点数,所以我不能使用 Gauss nb
【解决方案2】:

既然你说你正在使用nltk 库,你可以这样做:

from nltk.classify import NaiveBayesClassifier
from nltk.classify.scikitlearn import SklearnClassifier

x=dataset1[:,1:23] # features
y=dataset1[:,0] #classtypes 
xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.20)

classifier = NaiveBayesClassifier.train(xtrain)

y_predicted = classifier.classify(xtest)

这里,classify 属性与scikit-learn 算法中的predict 属性相同。


可用的属性如下:

Documentation here

【讨论】:

  • 你是对的,但我做错了。我的数据是分类的。所以我用二进制(真,假)的方式对其进行了编码。所以我现在不能使用 train_test_split 。无论如何,谢谢,但我失败了。对不起
  • 只考虑接受和支持我的回答,因为它解决了您描述的最初问题,因此其他人可能想要考虑它。最好的问候
猜你喜欢
  • 2017-04-14
  • 2017-06-25
  • 2019-04-02
  • 2013-12-01
  • 1970-01-01
  • 2016-09-28
  • 2018-03-18
  • 2018-05-20
  • 1970-01-01
相关资源
最近更新 更多