Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在训练/测试之后,如何使用全新的数据测试朴素贝叶斯分类器?_Python_Pandas_Machine Learning_Scikit Learn_Anaconda - Fatal编程技术网

Python 在训练/测试之后,如何使用全新的数据测试朴素贝叶斯分类器?

Python 在训练/测试之后,如何使用全新的数据测试朴素贝叶斯分类器?,python,pandas,machine-learning,scikit-learn,anaconda,Python,Pandas,Machine Learning,Scikit Learn,Anaconda,我训练/测试了一个二进制分类器,根据类将输出设置为0或1。它就像一个垃圾邮件分类器。现在,我有一些额外的数据,我只想测试它们并得到一个输出数组,如: [0 1 0 0 0... 1 0] 以下是我所做的: 我使用pandas库创建了一个数据帧 def dataFromDirectory(path): rows = [] index = [] for filename, message in readFiles(path): rows.append({'r

我训练/测试了一个二进制分类器,根据类将输出设置为0或1。它就像一个垃圾邮件分类器。现在,我有一些额外的数据,我只想测试它们并得到一个输出数组,如:

[0 1 0 0 0... 1 0]
以下是我所做的:

我使用pandas库创建了一个数据帧

def dataFromDirectory(path):
    rows = []
    index = []
    for filename, message in readFiles(path):
        rows.append({'resume': message})
        index.append(filename)

    return DataFrame(rows, index=index)

test= DataFrame({'resume':[]})
test=test.append(dataFromDirectory(r'<folder path>'))
将在两列中分别给出txt文件的文件路径和内容的5x2数组。大概是这样的:

         | data   |
<path1>  | <text> |
<path2>  | <text> |
<path3>  | <text> |
 .  
 .
 .
我得到的输出是

[0]

我做错了什么?请注意,我使用的是Python3。

您应该发布完整的代码和一些
test
的示例。什么是Tfidf向量机?@VivekKumar是的,它是Tfidf向量机什么是
测试
。我的意思是它包含文本列表还是单个文本,或者文件列表?打印
test
testtf
的形状。testtf是在我使用Tf-Idf对测试进行矢量化之后。这应该像垃圾邮件分类器一样工作。比如,我有10个.txt文件,当我执行mnb.predict(testtf)时,输出应该是一个包含10个元素的数组。发布
test.shape
并尝试
testtf=tf.transform(test['resume'])
testtf=tf.transform(test) #tf is the Tf-Idf vectorizer
pred1=mnb.predict(testtf) #MultinomialNaiveBayes is mnb
[0]