-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
64 lines (39 loc) · 1.44 KB
/
test.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pickle
import pandas as pd
import numpy as np
import sklearn as sk
from sklearn import linear_model
from sklearn.utils import shuffle
import matplotlib.pyplot as pyplot
from matplotlib import style
db = pd.read_csv("student-mat.csv", sep=";")
db = db[["G1", "G2", "G3", "failures", "absences", "studytime"]]
target = "G3"
x = np.array(db.drop([target], 1))
y = np.array(db[target])
x_train, x_test, y_train, y_test = sk.model_selection.train_test_split(x, y, test_size=0.1)
'''best = 0
for _ in range(100):
x_train, x_test, y_train, y_test = sk.model_selection.train_test_split(x, y, test_size=0.1)
my_model = linear_model.LinearRegression()
my_model.fit(x_train, y_train)
accuracy = my_model.score(x_train, y_train)
predictions = my_model.predict(x_test)
print(round(accuracy * 100))
if accuracy > best:
with open("mathstudents.pickle", "wb") as f:
pickle.dump(my_model, f)'''
read_in_pickle = open("mathstudents.pickle", "rb")
my_model = pickle.load(read_in_pickle)
accuracy = my_model.score(x_train, y_train)
predictions = my_model.predict(x_test)
print("Prediction accuracy: " + str(round(accuracy * 100)) + "%")
print("Coefficients: " + str(my_model.coef_))
for x in range(len(predictions)):
print(round(predictions[x]), y_test[x])
attribute = 'G1'
style.use("ggplot")
pyplot.scatter(db[attribute], db['G3'])
pyplot.xlabel(attribute)
pyplot.ylabel('Final Grade (G3)')
pyplot.show()