-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtrain.py
More file actions
36 lines (25 loc) · 893 Bytes
/
train.py
File metadata and controls
36 lines (25 loc) · 893 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
29
30
31
32
33
34
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import recall_score, precision_score
import json
import os
import numpy as np
import pandas as pd
# Read in data
X_train = np.genfromtxt("data/train_features.csv")
y_train = np.genfromtxt("data/train_labels.csv")
X_test = np.genfromtxt("data/test_features.csv")
y_test = np.genfromtxt("data/test_labels.csv")
# Fit a model
clf = MLPClassifier(random_state=0, max_iter=30)
clf.fit(X_train,y_train)
# Get overall accuracy
acc = clf.score(X_test, y_test)
# Get precision and recall
y_score = clf.predict(X_test)
prec = precision_score(y_test, y_score)
rec = recall_score(y_test,y_score)
# Get the loss
loss = clf.loss_curve_
pd.DataFrame(loss, columns=["loss"]).to_csv("loss.csv", index=False)
with open("metrics.json", 'w') as outfile:
json.dump({ "accuracy": acc, "precision":prec,"recall":rec}, outfile)