擅长:python、mysql、java
<p>在<code>if</code>语句中,您试图将<code>prediction</code>变量的值与字符串进行比较。这没有意义,因为<code>prediction</code>变量的类型应该是<code>ndarray</code>-这是scikit learn中朴素贝叶斯分类器的<code>predict()</code>方法的返回类型</p>
<p>此外,稍后在代码中,您将尝试将字符串附加到整数(<code>tweet_pred</code>,该整数在for循环中重新定义)。这也行不通</p>
<p>要将<code>prediction</code>的内容保存在文件中(每行一个值),可以执行以下操作:</p>
<pre><code>prediction = classifer.predict(tweet_input_transformed)
with open("\path\to\a\file.txt", 'w') as f:
f.write('\n'.join(prediction))
</code></pre>