This dataset is from the UCI Machine Learning Repository and is comprised of student performance inforation. The data contains the following features:
school
- student’s school (binary: ‘GP’ - Gabriel Pereira or ‘MS’ - Mousinho da Silveira)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 - <15 min., 2 - 15 to 30 min., 3 - 30 min. to 1 hour, or 4 - >1 hour)studytime
- weekly study time (numeric: 1 - <2 hours, 2 - 2 to 5 hours, 3 - 5 to 10 hours, or 4 - >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)The task associated with this dataset is regression to determine the the grades related with the course subjects:
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, output target)df_mat = read.table("https://raw.githubusercontent.com/mkivenson/Business-Analytics-Data-Mining/master/Final%20Project/student-mat.csv",sep=";",header=TRUE)
df_por = read.table("https://raw.githubusercontent.com/mkivenson/Business-Analytics-Data-Mining/master/Final%20Project/student-por.csv",sep=";",header=TRUE)
The goal of this project is to use features from a student’s personal life and activities to predict grades in Math and Portuguese classes. Feature importance and explainability will be particularly useful, as it will indicate which factors are most valuable in grades. Two datasets will be used containing the same features - one for Math grades (df_mat
) and one for Portuguese grades (df_por
). There is some overlap in students between the Math and Portuguese classes, so separate models will be created for each dataset. This will also be a useful indicator of whether feature importance varies between math and language skills.
The first step to predicting test scores for math and portuguese classes is data exploration and preprocessing. There are no missing values in the dataset, so no imputation is needed. However, there are many categorical and ordinal variables in the dataset. Categorical variables will be encoded prior to use in linear models, but ordinal variables will be kept as-is. To encode categorical variables, one hot encoding will be used to create dummy variables.
We then divide our variables into two separate datasets for Math and Portugues and divide each of those datasets into test and train data. We used stepwise regression model to build a linear model using our train data and test their performance on test data.
The correlation plots below show correlation on numeric columns only, and indicate very limited collinearity in the dataset. The last three columns/rows are the test scores - scores are highly correlated with each other.
df_mat<-as.data.frame(df_mat)
corrplot(cor(df_mat[,sapply(df_mat, is.numeric)], use = "complete.obs"), method="color", type="lower", tl.col = "black", tl.srt = 5)
df_por<-as.data.frame(df_por)
corrplot(cor(df_por[,sapply(df_por, is.numeric)], use = "complete.obs"), method="color", type="lower", tl.col = "black", tl.srt = 5)