Сообщение об ошибке при попытке train_test_split на выводе tfidxvectoizer - PullRequest
0 голосов
/ 23 марта 2020

Я пытаюсь векторизовать текст, содержащий столбец 'title' этого кадра данных. Который, кажется, завершить успешно. Я думаю, извлечь цель для моего прогноза. Когда я запускаю train_test_split, я получаю следующую ошибку:

TypeError: '<' не поддерживается между экземплярами 'str' и 'float' </p>

# Import dependencies
import pandas as pd
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import GaussianNB

volunteer = pd.read_csv('https://assets.datacamp.com/production/repositories/1816/datasets/668b96955d8b252aa8439c7602d516634e3f015e/volunteer_opportunities.csv')

# Take the title text
title_text = volunteer['title']

# Create the vectorizer method
tfidf_vec = TfidfVectorizer()

# Transform the text into tf-idf vectors
text_tfidf = tfidf_vec.fit_transform(title_text)

# Split the dataset according to the class distribution of category_desc
y = volunteer["category_desc"]

#category_enc = pd.get_dummies(volunteer['category_desc'])
X_train, X_test, y_train, y_test = train_test_split(text_tfidf.toarray(), y, stratify=y)

# Create Naive Beyes model
nb = GaussianNB()

# Fit the model to the training data
nb.fit(X_train, y_train)

# Print out the model's accuracy
print(nb.score(X_test, y_test))

Есть ли у кого-нибудь решение и или знаете причину этой ошибки?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...