-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsvm
More file actions
28 lines (23 loc) · 796 Bytes
/
lsvm
File metadata and controls
28 lines (23 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score, classification_report
# Load Data
train = pd.read_csv('path/data.csv')
test = pd.read_csv('path/data.csv')
# Training and Testing Set Assignment
X = train.description
y = train.label
X_train = train.description
X_test = test.description
y_train = train.label
y_test = test.label
# LSVM Modeling
SVC = Pipeline([('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('clf', LinearSVC()),
])
SVC.fit(X_train, y_train)
y_pred = SVC.predict(X_test)
print('accuracy %s' % accuracy_score(y_pred, y_test))
print(classification_report(y_test, y_pred))