<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import linear_model
from sklearn.metrics import accuracy_score
import pickle

df = pd.read_csv("student-mat.csv", sep=";")

# X values are the variables that you input
X = df[["traveltime", "studytime", "failures", "absences","G1", "G2"]]
# Y is what you are trying to measure
Y = df["G3"]

X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, shuffle=True)

lin_reg = linear_model.LinearRegression()

lin_reg.fit(X_train,y_train)

# Model can be saved using a pickle file
pickle.dump(lin_reg, open("model", 'wb'))

predicted = list(map(round,lin_reg.predict(X_test)))

print(accuracy_score(y_test, predicted))

# returns an array of weights for the hypothesis function
print(lin_reg.coef_)
print(lin_reg.intercept_) # Y intercept of the hypothesis function

print(X_test)
print(y_test)

for i in range(len(predicted)):
  print(f"PREDICTED:{round(predicted[i])} , Actual:{list(y_test)[i]}")
# Saved model can be retrieved
model = pickle.load(open("model", 'rb'))

# put in the values of the different labeles (eg. traveltime = 0, studytime = 3 ....)
sample_tuple = [[1,6,0,4,15,16]]

tuple_df = pd.DataFrame(sample_tuple, columns=["traveltime", "studytime", "failures", "absences", "G1", "G2"])

val = model.predict(tuple_df)

print(val[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.142353770260747, 'fraction_numerical': 0.012684989429175475, 'mean_word_length': 6.553191489361702, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '150759', 'license': 'MIT', 'n_tokens_mistral': 527, 'n_tokens_neox': 515, 'n_words': 130, 'path': 'Grade Prediction with Linear Regression.ipynb', 'repo_name': 'OmPanchal/Linear-Regression', 'size': '1419'}