Python 3.x 多标签分类器代码错误

Python 3.x 多标签分类器代码错误,python-3.x,scikit-learn,naivebayes,multilabel-classification,tfidfvectorizer,Python 3.x,Scikit Learn,Naivebayes,Multilabel Classification,Tfidfvectorizer,我正在尝试训练一个分类器来按电影类型给电影贴标签。这部电影的情节可能不止一种类型。 当我试图找出测试集中每种电影类型的准确度时,我总是收到这个错误消息。 错误消息: 类型错误:“FramePlotMethods”对象不可编辑 有人能解释一下我做错了什么吗 我从你那里得到了电影资料 这是一开始的代码 df = pd.read_csv("movies_genres_en.csv", delimiter='\t') df.drop('plot_lang', axis=1, inplace=True)

我正在尝试训练一个分类器来按电影类型给电影贴标签。这部电影的情节可能不止一种类型。 当我试图找出测试集中每种电影类型的准确度时,我总是收到这个错误消息。 错误消息: 类型错误:“FramePlotMethods”对象不可编辑

有人能解释一下我做错了什么吗

我从你那里得到了电影资料

这是一开始的代码

df = pd.read_csv("movies_genres_en.csv", delimiter='\t')
df.drop('plot_lang', axis=1, inplace=True)
df.info()

# using for loop get a count of movies by genre
df_genres = df.drop(['plot', 'title'], axis=1)
counts = []
categories = list(df_genres.columns.values)
for i in categories:
counts.append((i, df_genres[i].sum()))
df_stats = pd.DataFrame(counts, columns = ['genre','#movies'])
df_stats

# Create a fuction to clean the text
def clean_text(text):
text = text.lower()
text = re.sub(r"what's", "what is ", text)
text = re.sub(r"\'s", " ", text)
text = re.sub(r"\'ve", " have ", text)
text = re.sub(r"can't", "can not ", text)
text = re.sub(r"n't", " not ", text)
text = re.sub(r"i'm", "i am ", text)
text = re.sub(r"\'re", " are ", text)
text = re.sub(r"\'d", " would ", text)
text = re.sub(r"\'ll", " will ", text)
text = re.sub(r"\'scuse", " excuse ", text)
text = re.sub('\W', ' ', text)
text = re.sub('\s+', ' ', text)
text = text.strip(' ')
return text    

# clean up the text in plot
df['plot'] = df['plot'].map(lambda com : clean_text(com))
将数据拆分为训练集和测试集 我在运行最后一个代码块时出现此错误 类型错误:“FramePlotMethods”对象不可编辑


我在创建df时做错了什么?

这里有一个“可运行”的示例会很好。我真的不想花时间猜测您的数据帧中有什么。图像不够,无法保证您在代码中正确设置了
df
,并且图像中只有3行,最后几列被截断。你能给我们一个我们可以用开箱即用的片段吗?如果太难的话,你不必构建完整的数据帧……但是给我们一些东西。我在上面添加了完整的代码。你能告诉我df有什么问题吗?Plot是数据框中的一列。然而,这也是大熊猫的一种方法。因此,您可能会将python与这些命令train.plot和test.plot混淆。它们看起来也有点像您忘记了圆括号,例如test.plot(),并试图将plot作为属性。有道理…非常感谢KRKirov
train, test = train_test_split(df, random_state=42, test_size = 0.33, 
shuffle=True)
x_train = train.plot
x_test = test.plot

# Define a pipeline combining a text feature extractor with multi lable 
classifier
NB_pipeline = Pipeline([
            ('tfidf', TfidfVectorizer(stop_words='english')),
            ('clf', OneVsRestClassifier(MultinomialNB(
                fit_prior=True, class_prior=None))),
        ])

NB_pipeline.fit(x_train, train[genre])
prediction = NB_pipeline.predict(x_test)
accuracy_score(test[genre], prediction)