python - 如何在本地主机上运行 textblob?
问题描述
在我的定位主机上,如果我运行简单的打印语句,它工作正常。但我想使用 textblob 进行情绪分析。为此,我试图在我的本地主机上运行以下代码,但它显示错误。
代码:
#!C:\fname lname\AppData\Local\Programs\Python\Python37-32\python.exe
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
train = [
('I love this sandwich.', 'pos'),
('This is an amazing place!', 'pos'),
('I feel very good about these beers.', 'pos'),
('This is my best work.', 'pos'),
("What an awesome view", 'pos'),
('I do not like this restaurant', 'neg'),
('I am tired of this stuff.', 'neg'),
("I can't deal with this", 'neg'),
('He is my sworn enemy!', 'neg'),
('My boss is horrible.', 'neg')
]
test = [
('The beer was good.', 'pos'),
('I do not enjoy my job', 'neg'),
("I ain't feeling dandy today.", 'neg'),
("I feel amazing!", 'pos'),
('Gary is a friend of mine.', 'pos'),
("I can't believe I'm doing this.", 'neg')
]
cl = NaiveBayesClassifier(train)
# Classify some text
print(cl.classify("Their burgers are amazing.")) # "pos"
print(cl.classify("I don't like their pizza.")) # "neg"
# Classify a TextBlob
blob = TextBlob("The beer was amazing. But the hangover was horrible. "
"My boss was not pleased.", classifier=cl)
print(blob)
print(blob.classify())
for sentence in blob.sentences:
print(sentence)
print(sentence.classify())
# Compute accuracy
print("Accuracy: {0}".format(cl.accuracy(test)))
# Show 5 most informative features
cl.show_informative_features(5)
我觉得问题是这些陈述。不知道如何修复它。不确定我是否需要导入任何库并将其放置在放置脚本的位置。
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
错误显示为:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: nltk.py
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.
7
解决方案
推荐阅读
- powershell - PowerShell SFTP 上传到特定端口号
- apache-flink - 如何在不同的节点上运行 Flink Job Manager 和 Task Manager?
- javascript - 运行一些 Ajax 代码在控制台中给出了一个未定义的值
- python - 可视化 cumsum python
- typescript - Maybe monad 的另一个名字是什么?
- druid - 将来自多个 kafka 主题的数据提取到 druid 中的单个数据源中
- ruby-on-rails - ActiveRecord 未提供所有数据库列
- android - Room RxJava Flowable 在插入后不发出更新
- html - 关键帧和悬停编码挑战
- r - 为什么注释会影响每个 bin 中的密度数?