-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmlp-nn.py
More file actions
executable file
·38 lines (28 loc) · 1.11 KB
/
mlp-nn.py
File metadata and controls
executable file
·38 lines (28 loc) · 1.11 KB
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
29
30
31
32
33
34
35
36
37
38
from sklearn.metrics import accuracy_score
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.neural_network import MLPClassifier
from nltk.corpus import stopwords
from stop_words import get_stop_words
import sys
sys.path.append('.')
import utils
max_features = 3000
print "Loading data ..."
x_train, x_test, y_train, y_test = utils.load_data()
# x_train, x_test, y_train, y_test = utils.load_data2()
sw = stopwords.words('english') + get_stop_words("english")
print "Extracting features..."
vectorizer = CountVectorizer(analyzer = "word",
max_features = max_features)
x_train, x_test, y_train, y_test = utils.extract_features(x_train, x_test, y_train, y_test, vectorizer)
print "Creating and training the model..."
model = MLPClassifier(solver='sgd',
hidden_layer_sizes=(10, 10, 10),
random_state=5,
verbose=True)
model.fit(x_train, y_train)
print "Predicting..."
y_pred = model.predict(x_test)
print "Evaluating..."
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))