Я пытаюсь сделать прогноз для pandas фрейма данных в Python. Почему-то CountVectorizer не может преобразовать данные. Кто-нибудь знает, в чем проблема?
Это мой код:
filename = 'final_model.sav'
print(response.status_code)
data = response.json()
print(data)
dictionary = pd.read_json('rating_company_small.json', lines=True)
dictionary_df = pd.DataFrame()
dictionary_df["comment text"] = dictionary["comment"]
data = pd.DataFrame.from_dict(json_normalize(data), orient='columns')
print(data)
df = pd.DataFrame()
df["comment text"] = data["Text"]
df["status"] = data["Status"]
print(df)
Processing.dataframe_cleaning(df)
comment_data = df['comment text']
tfidf = CountVectorizer()
tfidf.fit(dictionary_df["comment text"])
Test_X_Tfidf = tfidf.transform(df["comment text"])
print(comment_data)
print(Test_X_Tfidf)
loaded_model = pickle.load(open(filename, 'rb'))
predictions_NB = loaded_model.predict(Test_X_Tfidf)
Это фрейм данных:
comment text status
0 [slecht, bedrijf] string
1 [leuk, bedrijfje, goed, behandeld] Approved
2 [leuk, bedrijfje, goed, behandeld] Approved
3 [leuk, bedrijfje] Approved
полное сообщение об ошибке:
Traceback (most recent call last):
File "Request.py", line 36, in <module>
Test_X_Tfidf = tfidf.transform(df["comment text"])
File "C:\Users\junio\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 1112, in transform
_, X = self._count_vocab(raw_documents, fixed_vocab=True)
File "C:\Users\junio\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 970, in _count_vocab
for feature in analyze(doc):
File "C:\Users\junio\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 352, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words)
File "C:\Users\junio\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 256, in <lambda>
return lambda x: strip_accents(x.lower())
AttributeError: 'list' object has no attribute 'lower'
Я ожидаю, что он вернет прогнозы на фрейм данных.