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) 我有以下格式的大量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)
看起来我的格式正确,为什么这不起作用?