-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson1.py
36 lines (25 loc) · 926 Bytes
/
Lesson1.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
import pandas as pd
import numpy as np
import sklearn
import sklearn.model_selection as ms
from sklearn import linear_model
import pickle
data = pd.read_csv('F:/NEW/importent folder/main folder/projects for github/AI and AI in Python/codes and files/student-mat.csv', sep=';')
print(data.head())
data = data[['G1', 'G2', 'G3', 'studytime', 'failures', 'absences']]
predict = "G3"
# Assuming you have your data defined here
x = np.array(data.drop([predict], 1))
y = np.array(data[predict])
best=0
for _ in range(100):
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)
linear = linear_model.LinearRegression()
linear.fit(x_train, y_train)
acc = linear.score(x_test, y_test)
print(acc)
if (acc > best):
best=acc
with open("studentmodel.pickle", "wb") as f:
pickle.dump(linear, f)
print("Best=", best)