[英]machine learning algorithm for text classification i get pb
def TextClassification(a):
import pandas as pd
df = pd.read_excel('../Desktop/Stage/Classeur1.xlsx')
#Removing NULL element
df=df[pd.notnull(df['Réclamation'])]
df=df[pd.notnull(df['Catégorie'])]
#Removing punctuation
df['Réclamation'] = [''.join(c for c in s if c not in string.punctuation) for s in df['Réclamation']]
df['Catégorie'] = [''.join(c for c in s if c not in string.punctuation) for s in df['Catégorie']]
#Removing é è and all numbers
ch = ['0','1','2','3','4','5','6','7','8','9']
for c in ch:
df['Réclamation'] = [w.replace(c, '') for w in df['Réclamation']]
df['Catégorie'] = [w.replace(c, '') for w in df['Catégorie']]
df['Réclamation']= [w.replace('è', 'e') for w in df['Réclamation']]
df['Réclamation']= [w.replace('é', 'e') for w in df['Réclamation']]
df['Catégorie']= [w.replace('è', 'e') for w in df['Catégorie']]
df['Catégorie']= [w.replace('é', 'e') for w in df['Catégorie']]
#Lower case
df['Réclamation']=df['Réclamation'].apply(lambda x: " ".join(x.lower() for x in x.split()))
df['Catégorie']=df['Catégorie'].apply(lambda x: " ".join(x.lower() for x in x.split()))
df['category_id'] = df['Catégorie'].factorize()[0]
category_id_df = df[['Catégorie', 'category_id']].sort_values('category_id')
category_to_id = dict(category_id_df.values)
id_to_category = dict(category_id_df[['category_id', 'Catégorie']].values)
#library for data preprocessing and maodel building
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.svm import LinearSVC
#split data(train/test)
X_train, X_test, y_train, y_test = train_test_split(df['Réclamation'], df['Catégorie'], random_state = 0)
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(X_train)
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
clf = LinearSVC().fit(X_train_tfidf, y_train)
return(print(clf.predict(count_vect.transform(a)))
How can I fix this: I get EOF where is the pb pls in the last line help, and what means EOF?我该如何解决这个问题:我得到 EOF 最后一行帮助中的 pb pls 在哪里,EOF 是什么意思?
File "<ipython-input-25-e6d13da1f205>", line 50
return(print(clf.predict(count_vect.transform(a)))
^
SyntaxError: unexpected EOF while parsing
You are missing a )
你缺少一个
)
return(print(clf.predict(count_vect.transform(a)))
^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.