I created a neural network using linear regression that would be able to predict the grades that students would get after how many hours they spent studying. I then used the matplotlib library to plot all of the data on a graph to see what it looks like.
import pandas as pd
import numpy as np
import sklearn
from sklearn import linear_model
import matplotlib.pyplot as pyplot
import pickle
from matplotlib import style
data = pd.read_csv("student-mat.csv", sep=";")
data = data[["G1", "G2", "G3", "studytime", "failures", "absences"]]
predict = "G3" #predicting the final grade
X = np.array(data.drop([predict], 1)) #return new data frame wo g3
Y = np.array(data[predict])
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(X, Y, test_size=0.1) #spliting up attributes into arrays
pickle_in = open("studentmodel.pickel", "rb")
linear = pickle.load(pickle_in)
#y = mx + b
print("Co: \n", linear.coef_)
print("Intercept: \n", linear.intercept_)
predictions = linear.predict(x_test)
for x in range(len(predictions)):
print(predictions[x], x_test[x], y_test[x])
p = 'studytime'
style.use("ggplot")
pyplot.scatter(data[p], data['G3'])
pyplot.xlabel(p)
pyplot.ylabel("Final Grade")
pyplot.show()