小编NIH*_*NIH的帖子

Naive Bayes Classifier error

Hey I am trying to use a Naive Bayes classifier to classify some text. I am using NLTK. Whenever I test the classifier using the classify() method it always returns the correct classification for the first item, and the same classification for every other line of text I classify. The following is my code:

from nltk.corpus import movie_reviews
from nltk.tokenize import word_tokenize
import nltk
import random
import nltk.data

documents = [(list(movie_reviews.words(fileid)), category)
for category in movie_reviews.categories()
for fileid in movie_reviews.fileids(category)] …
Run Code Online (Sandbox Code Playgroud)

python nltk

7
推荐指数
1
解决办法
1862
查看次数

检查字符是否等于python中的引号

我在python中迭代一个字符串,我想检查每个字符,看它是否等于".我该怎么做呢?

python

3
推荐指数
1
解决办法
2万
查看次数

将UTC时间转换为python datetime

我有以下格式的大量UTC时间戳: 2012-04-30T23:08:56+00:00 我想将它们转换为python datetime对象,但遇到了麻烦.

我的代码:

for time in data:
    pythondata[i]=datetime.strptime(time,"%y-%m-%dT%H:%M:%S+00:00")
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ValueError: time data '2012-03-01T00:05:55+00:00' does not match format '%y-%m-%dT%H:%M:%S+00:00'
Run Code Online (Sandbox Code Playgroud)

看起来我的格式正确,为什么这不起作用?

python datetime utc rfc3339

2
推荐指数
1
解决办法
5806
查看次数

标签 统计

python ×3

datetime ×1

nltk ×1

rfc3339 ×1

utc ×1