# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# !pip install mlxtend

import pandas as pd
import pandas_profiling
import numpy as np
import matplotlib.pyplot as plt
# %matplotlib inline
import seaborn as sns
import matplotlib.ticker as mtick
from sklearn.linear_model import LinearRegression
from mlxtend.plotting import plot_linear_regression
from sklearn.metrics import mean_absolute_error

data = pd.read_csv('Data/ml.csv')

data.info()

data['is_banked'] = data['is_banked'].apply(str)
data['code_module'] = data['code_module'].apply(str)
data['code_presentation'] = data['code_presentation'].apply(str)

# Separate the target and the rest of the columns.

data_data = data[['date_submitted', 'num_of_prev_attempts', 'studied_credits', 'module_presentation_length']]
data_target = data["score"]

# Initialize the model in the variable `data_model`

data_model = LinearRegression()

# Fit the model and print the intercept and coefficients of the model. 

# +
# Your code here:
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test=train_test_split(data_data, data_target, test_size=0.2)
# -

data_model.fit(X_train, y_train)
print('Intercept: {}'.format(data_model.intercept_))
print ('')
print('Coef : {}'.format(data_model.coef_))

from sklearn.metrics import r2_score

# +
# Predict para el train

y_pred=data_model.predict(X_train)

r2 = r2_score(y_train, y_pred)
mae = mean_absolute_error(y_train, y_pred)
print ('TRAIN MODEL METRICS:')
print('The R2 score is: ' + str(r2))
print('The MAE score is: ' + str(mae))

plt.scatter(y_train, y_pred)
plt.plot([0,100], [0,100], color='red')
plt.show()

# +
# Predict para el test

y_test_pred=data_model.predict(X_test)

r2 = r2_score(y_train, y_pred)
mae = mean_absolute_error(y_test, y_test_pred)
print ('TRAIN MODEL METRICS:')
print('The R2 score is: ' + str(r2))
print('The MAE score is: ' + str(mae))

plt.scatter(y_test, y_test_pred)
plt.plot([0,100], [0,100], color='red')
plt.show()
# -

# Clearly there are no linear realtions between our data.

StarcoderdataJupyterScriptsDedupFiltered