I want to create a program to do emotion classification using TF-IDF and SVM. Before classify the data, I have to split a dataset into data training and testing using stratified KFold. I've used the numpy array to store the texts (X) and labels (Y)
But it ended up with this error :
'ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multiclass-multioutput' instead.'
this code is running on python 3.7
this is my code :
labels = []
with open(path, encoding='utf-8') as in_file:
data = csv.reader(in_file)
for line in data:
labels.append(line[1])
label_np = np.array(labels)
lp = label_np.reshape(20,20)
# lp = label_np.transpose(0)
# print(lp)
result_preprocess_np = np.array(result_preprocess)
hp = result_preprocess_np.reshape(20,20)
model = LinearSVC(multi_class='crammer_singer')
total_svm = []
total_mat_svm = np.zeros((20,20))
kf = StratifiedKFold(n_splits=3)
kf.get_n_splits(hp, lp)
for train_index, test_index in kf.split(hp, lp):
# print('Train : ', test_index, 'Test : ', test_index)
x_train, x_test = hp[train_index], hp[test_index]
y_train, y_test = lp[train_index], lp[test_index]
vectorizer = TfidfVectorizer(min_df=5,
max_df=0.8,
sublinear_tf=True,
use_idf=True)
train_vector = vectorizer.fit_transform(x_train)
test_vector = vectorizer.transform(x_test)
model.fit(x_train, y_train)
result_svm = model.score(x_test, y_test)
print(result_svm)
I expect the result is the accuracy of classification.
Aucun commentaire:
Enregistrer un commentaire