text_plain_output_1.png
from Sastrawi.Stemmer.StemmerFactory import StemmerFactory

from sklearn import svm

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics import accuracy_score

from sklearn.preprocessing import LabelEncoder

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

factory = StemmerFactory()
stemmer = factory.create_stemmer()
Encoder = LabelEncoder()
Tfidf_vect = TfidfVectorizer()

data_train = pd.read_csv('../input/indonesiafalsenews/Data_latih.csv')

false_news = data_train[data_train['label'] == 1].sample(frac=1)
true_fact = data_train[data_train['label'] == 0]
df = true_fact.append(false_news[:len(true_fact) + 200])
df

feature = df['narasi']
label = df['label']

lower = [stemmer.stem(row.lower()) for row in feature]
lower

y_train = Encoder.fit_transform(y_train)
y_test = Encoder.fit_transform(y_test)
y_train

Tfidf_vect.fit([''.join(row) for row in X_train])

X_train_Tfidf = Tfidf_vect.transform([' '.join(row) for row in X_train])
X_test_Tfidf = Tfidf_vect.transform([' '.join(row) for row in X_test])

SVM = svm.SVC(C=1.0, kernel='linear', degree=1, gamma='auto', verbose=True)
SVM.fit(X_train_Tfidf, y_train)
predictions_SVM = SVM.predict(X_test_Tfidf)
print('SVM Accuracy Score -> ', accuracy_score(predictions_SVM, y_test) * 100)