<jupyter_start><jupyter_text>There are 33 columns:school: student's school (binary: 'GP' - <NAME> or 'MS' - <NAME>)sex: student's sex (binary: 'F' - female or 'M' - male)age: student's age (numeric: from 15 to 22)address: student's home address type (binary: 'U' - urban or 'R' - rural)famsize: family size (binary: 'LE3' - less or equal to 3 or 'GT3' - greater than 3)Pstatus: parent's cohabitation status (binary: 'T' - living together or 'A' - apart)Medu: mother's education (numeric: 0 - none, 1 - primary education (4th grade), 2 â€“ 5th to 9th grade, 3 â€“ secondary education or 4 â€“ higher education)Fedu: father's education (numeric: 0 - none, 1 - primary education (4th grade), 2 â€“ 5th to 9th grade, 3 â€“ secondary education or 4 â€“ higher education)Mjob: mother's job (nominal: 'teacher', 'health' care related, civil 'services' (e.g. administrative or police), 'at_home' or 'other')Fjob: father's job (nominal: 'teacher', 'health' care related, civil 'services' (e.g. administrative or police), 'at_home' or 'other')reason: reason to choose this school (nominal: close to 'home', school 'reputation', 'course' preference or 'other')guardian: student's guardian (nominal: 'mother', 'father' or 'other')traveltime: home to school travel time (numeric: 1 - 1 hour)studytime: weekly study time (numeric: 1 - 10 hours)failures: number of past class failures (numeric: n if 1<=n<3, else 4)schoolsup: extra educational support (binary: yes or no)famsup: family educational support (binary: yes or no)paid: extra paid classes within the course subject (Math or Portuguese) (binary: yes or no)activities: extra-curricular activities (binary: yes or no)nursery: attended nursery school (binary: yes or no)higher: wants to take higher education (binary: yes or no)internet: Internet access at home (binary: yes or no)romantic: with a romantic relationship (binary: yes or no)famrel: quality of family relationships (numeric: from 1 - very bad to 5 - excellent)freetime: free time after school (numeric: from 1 - very low to 5 - very high)goout: going out with friends (numeric: from 1 - very low to 5 - very high)Dalc: workday alcohol consumption (numeric: from 1 - very low to 5 - very high)Walc: weekend alcohol consumption (numeric: from 1 - very low to 5 - very high)health: current health status (numeric: from 1 - very bad to 5 - very good)absences: number of school absences (numeric: from 0 to 93)G1: first period grade (numeric: from 0 to 20)G2: second period grade (numeric: from 0 to 20)G3: final grade (numeric: from 0 to 20)<jupyter_code>data=pd.read_csv("/content/student-mat.csv")
data.head()<jupyter_output><empty_output><jupyter_text>Final grade<jupyter_code>data['G3'].describe()
import seaborn as sns
import matplotlib.pyplot as plt
demo= sns.countplot(data['G3'])
demo.axes.set_title('Distribution of Final grade of students', fontsize = 35)
demo.set_xlabel('Final Grade', fontsize = 20)
demo.set_ylabel('Count', fontsize = 20)
plt.show()<jupyter_output>/usr/local/lib/python3.6/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>Something seems off here. Apart from the high number of students scoring 0, the distribution is normal as expected. Maybe the value 0 is used in place of null. Or maybe the students who did not appear for the exam, or were not allowed to sit for the exam due to some reason are marked as 0. We cannot be sure. Let us check the table for null values<jupyter_code>data.isnull().any()
data.isnull().sum()
male_student = len(data[data['sex'] == 'M'])
female_student= len(data[data['sex'] == 'F'])
print('Number of male students:',male_student)
print('Number of female students:',female_student)
demo= sns.countplot('age',hue='sex', data=data)
demo.axes.set_title('age groups',fontsize=30)
demo.set_xlabel("Age",fontsize=30)
demo.set_ylabel("Count",fontsize=20)
plt.show()
demo = sns.countplot(data['address'])
demo.axes.set_title('Urban Vs rural students', fontsize = 30)
demo.set_xlabel('Address', fontsize = 20)
demo.set_ylabel('Count', fontsize = 20)
plt.show()
data.corr()['G3'].sort_values()<jupyter_output><empty_output><jupyter_text>From the data above, let's create one more column to get the average grade from G1 to G3 (3 years average):<jupyter_code>data['GradeAvg'] = (data['G1'] + data['G2'] + data['G3']) / 3<jupyter_output><empty_output><jupyter_text>Next, we can drop school name and age feature because it is not a computational value<jupyter_code>data.drop(["school","age"], axis=1, inplace=True)
data.head()
data_dum=data
#Converting to categorical value
categorical_d = {'yes': 1, 'no': 0}
data_dum['schoolsup'] = data_dum['schoolsup'].map(categorical_d)
data_dum['famsup'] = data_dum['famsup'].map(categorical_d)
data_dum['paid'] = data_dum['paid'].map(categorical_d)
data_dum['activities'] = data_dum['activities'].map(categorical_d)
data_dum['nursery'] = data_dum['nursery'].map(categorical_d)
data_dum['higher'] = data_dum['higher'].map(categorical_d)
data_dum['internet'] = data_dum['internet'].map(categorical_d)
data_dum['romantic'] = data_dum['romantic'].map(categorical_d)

categorical_d = {'F': 1, 'M': 0}
data_dum['sex'] = data_dum['sex'].map(categorical_d)

# map the address data
categorical_d = {'U': 1, 'R': 0}
data_dum['address'] = data_dum['address'].map(categorical_d)

# map the famili size data
categorical_d = {'LE3': 1, 'GT3': 0}
data_dum['famsize'] = data_dum['famsize'].map(categorical_d)

# map the parent's status
categorical_d= {'T': 1, 'A': 0}
data_dum['Pstatus'] = data_dum['Pstatus'].map(categorical_d)

# map the parent's job
categorical_d = {'teacher': 0, 'health': 1, 'services': 2,'at_home': 3,'other': 4}
data_dum['Mjob'] = data_dum['Mjob'].map(categorical_d)
data_dum['Fjob'] = data_dum['Fjob'].map(categorical_d)

# map the reason data
categorical_d= {'home': 0, 'reputation': 1, 'course': 2,'other': 3}
data_dum['reason'] = data_dum['reason'].map(categorical_d)

# map the guardian data
categorical_d = {'mother': 0, 'father': 1, 'other': 2}
data_dum['guardian'] = data_dum['guardian'].map(categorical_d)

data_dum.columns
from sklearn.model_selection import train_test_split
x=data_dum.drop("G3",axis=1)
y=data_dum['G3']
data_dum['G3']

X_train, X_test, y_train, y_test = train_test_split(x,y, test_size = 0.20, random_state=44)
from sklearn.linear_model import LinearRegression 

L=LinearRegression()
L.fit(X_train, y_train)
y_pred=L.predict(X_test)
print(L.score(X_test, y_test))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13883480605062154, 'fraction_numerical': 0.019919125355698668, 'mean_word_length': 6.338461538461538, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '539972', 'license': 'Apache-2.0', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2257, 'n_words': 716, 'path': 'Students grade prediction using Machine Learning/Student_grade_prediction (1) (1).ipynb', 'repo_name': 'iitsunil/self-projects', 'size': '6700'}