How to train a classifier using list of list feature Python -
i have 2 variables called entity , label. entity variable store list of word, each element in list contain list well. list of list variable. list bi-gram feature need keep it.
i try train classifier using 2 variables. code far:
from sklearn import svm sklearn.feature_extraction.text import tfidfvectorizer entity = [[['prabowo subianto']], [['muhtar ependi']], [['nina zatulini']], [['partai gerindra']], [['persiba']], [['partai kebangkitan bangsa (pkb)'], ['partai kebangkitan'], ['kebangkitan bangsa'], ['bangsa ('], ['( pkb'], ['pkb )']], [['sman 3 kabupaten tangerang'], ['sman 3'], ['3 kabupaten'], ['kabupaten tangerang']], [['bandara changi singapura'], ['bandara changi'], ['changi singapura']], [['warung kopi kita'], ['warung kopi'], ['kopi kita']]] label = ['person', 'person', 'person', 'organization', 'organization', 'organization', 'location', 'location', 'location'] vectorizer = tfidfvectorizer(min_df=1) train_vector_entity = vectorizer.fit_transform(entity) train_vector_label = label classifier = svm.svc() classifier_word = classifier.fit(train_vector_entity,train_vector_label)
the error result:
attributeerror: 'list' object has no attribute 'lower'
what best way train classifier? thanks
just change row:
train_vector_entity = vectorizer.fit_transform([i[0][0] in entity])
Comments
Post a Comment