SVM algorithm training fitting doesnt work for text classification

25 Views Asked by At

I'm trying to fit the sentiment5 data which contains 2 varibales

  • "tweet" that has vectorized text data (using TF-IDF) and
  • "target" that has 1 and 0 for positive and negative.

I used the same train and test data on Naive bayes and logistic regression algorithms and I obtained the classification accuracy, however, when i try SVM, the code runs forever with no result.

#Feature extraction with TF-IDF:
tfidf = TfidfVectorizer(stop_words='english', max_df=0.75)
x = tfidf.fit_transform(sentiment5.tweet)
y = sentiment5.target

#Splitting the dataset into a train and test subsets 70/30 split:
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=52)

#Training the sentiment analysis model using Support Vector Machine SVM algorithm:
SVM = SVC(kernel='linear', random_state=42)
SVM.fit(x_train, y_train)

#Testing the model on test data to obtain the accuracy:
y_pred_SVM = SVM.predict(x_test)

#Evaluating the performance of SVM model:
SVM_accuracy = accuracy_score(y_test, y_pred_SVM)
SVM_classification_report = classification_report(y_test, y_pred_SVM)

#Displaying the model accuracy and report:
print("SVM accuracy with TF-IDF:", SVM_accuracy)
print("SVM classification report:\n", SVM_classification_report)
0

There are 0 best solutions below