lilpan commited on
Commit
bb0d5b0
·
verified ·
1 Parent(s): 551f2a0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +22 -0
README.md CHANGED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Assuming training and testing data are using the same names as we did in the skeleton code provided by the TA
2
+
3
+ X_train = dataset_train['title']
4
+ y_train = dataset_train['labels']
5
+
6
+ X_test = dataset_test['title']
7
+ y_test = dataset_test['labels']
8
+
9
+ from sklearn.feature_extraction.text import TfidfVectorizer
10
+ tfidf = TfidfVectorizer(max_features=5000, ngram_range=(1, 2), stop_words='english')
11
+ X_train_tfidf = tfidf.fit_transform(X_train)
12
+ X_test_tfidf = tfidf.transform(X_test)
13
+
14
+
15
+ from sklearn.svm import SVC
16
+ svm_model = SVC(kernel='linear', random_state=42)
17
+ svm_model.fit(X_train_tfidf, y_train)
18
+ y_pred = svm_model.predict(X_test_tfidf)
19
+ accuracy = accuracy_score(y_test, y_pred)
20
+ print(f"Random Forest Accuracy: {accuracy:.4f}")
21
+ print(classification_report(y_test, y_pred))
22
+