Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

train.py 893 B

You have to be logged in to leave a comment. Sign In
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
  1. from sklearn.neural_network import MLPClassifier
  2. from sklearn.metrics import recall_score, precision_score
  3. import json
  4. import os
  5. import numpy as np
  6. import pandas as pd
  7. # Read in data
  8. X_train = np.genfromtxt("data/train_features.csv")
  9. y_train = np.genfromtxt("data/train_labels.csv")
  10. X_test = np.genfromtxt("data/test_features.csv")
  11. y_test = np.genfromtxt("data/test_labels.csv")
  12. # Fit a model
  13. clf = MLPClassifier(random_state=0, max_iter=30)
  14. clf.fit(X_train,y_train)
  15. # Get overall accuracy
  16. acc = clf.score(X_test, y_test)
  17. # Get precision and recall
  18. y_score = clf.predict(X_test)
  19. prec = precision_score(y_test, y_score)
  20. rec = recall_score(y_test,y_score)
  21. # Get the loss
  22. loss = clf.loss_curve_
  23. pd.DataFrame(loss, columns=["loss"]).to_csv("loss.csv", index=False)
  24. with open("metrics.json", 'w') as outfile:
  25. json.dump({ "accuracy": acc, "precision":prec,"recall":rec}, outfile)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...