Final Project: Independent Data Intensive Research
ETR537
Author
Stella Jung
Published
December 10, 2023
1. Prepare
1.1 purpose
One of the most important aspects of education is students’ learning outcomes. Curriculum designers, teachers, and other stakeholders always aim to reach the most maximized results. There is a broad recognition of personal traits, family properties, and learning preference effect on students’ performance (Yılmaz & Sekeroglu ,2019; Rastrollo-Guerrero et al., 2020; Namoun & Alshanqiti, 2020). Recently, obtaining digitalized data regarding these factors has become easier as educational technologies develop. Instead, the need for methods that can treat massive amounts of data is getting more attention. Machine learning techniques are used to analyze massive amounts of digitalized data in education. In this context, this final project will examine a dataset to reveal the impact of factors on students’ performance.
Research question that will be examined in this final project is:
Which factors are most predictive of students’ performance(end-term grade)?
1.2 Dataset
The dataset used in this project was retrieved from the open resource (Kaggle.com). The title of the dataset is “Students’ performance (https://www.kaggle.com/datasets/joebeachcapital/students-performance).” I chose this dataset because it has many variables that affect students’ learning outcomes, and it was collected recently and opened to the public.
The data collectors didn’t specify how they collected this data and in what context. I can only find the information from the related published article that is listed on the Kaggle website. Yılmaz, and Sekeroglu (2019) stated they collected data from 101 students of a Turkish program of 3 courses of 2 faculties at Near East University, while the dataset on Kaggle website contains 145 cases. I couldn’t find the reason for the difference, but I used the enitre dataset in this project since the dataset is completed and clean. Their survey consisted of 30 items that asked about personal questions (9 items), family questions (6 items), and educational questions (13 items)
# load the packageslibrary(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.2 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(caret)
Loading required package: lattice
Attaching package: 'caret'
The following object is masked from 'package:purrr':
lift
library(ranger)library(e1071)library(tidylog)
Attaching package: 'tidylog'
The following objects are masked from 'package:dplyr':
add_count, add_tally, anti_join, count, distinct, distinct_all,
distinct_at, distinct_if, filter, filter_all, filter_at, filter_if,
full_join, group_by, group_by_all, group_by_at, group_by_if,
inner_join, left_join, mutate, mutate_all, mutate_at, mutate_if,
relocate, rename, rename_all, rename_at, rename_if, rename_with,
right_join, sample_frac, sample_n, select, select_all, select_at,
select_if, semi_join, slice, slice_head, slice_max, slice_min,
slice_sample, slice_tail, summarise, summarise_all, summarise_at,
summarise_if, summarize, summarize_all, summarize_at, summarize_if,
tally, top_frac, top_n, transmute, transmute_all, transmute_at,
transmute_if, ungroup
The following objects are masked from 'package:tidyr':
drop_na, fill, gather, pivot_longer, pivot_wider, replace_na,
spread, uncount
The following object is masked from 'package:stats':
filter
library(dataedu)
data <-read_csv("StudentsPerformance_with_headers.csv")
New names:
Rows: 145 Columns: 33
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(1): STUDENT ID dbl (32): Student Age, Sex, Graduated high-school type,
Scholarship type, Ad...
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `Reading frequency` -> `Reading frequency...19`
• `Reading frequency` -> `Reading frequency...20`
glimpse(data)
Rows: 145
Columns: 33
$ `STUDENT ID` <chr> "S…
$ `Student Age` <dbl> 2,…
$ Sex <dbl> 2,…
$ `Graduated high-school type` <dbl> 3,…
$ `Scholarship type` <dbl> 3,…
$ `Additional work` <dbl> 1,…
$ `Regular artistic or sports activity` <dbl> 2,…
$ `Do you have a partner` <dbl> 2,…
$ `Total salary if available` <dbl> 1,…
$ `Transportation to the university` <dbl> 1,…
$ `Accommodation type in Cyprus` <dbl> 1,…
$ `Mother’s education` <dbl> 1,…
$ `Father’s education` <dbl> 2,…
$ `Number of sisters/brothers` <dbl> 3,…
$ `Parental status` <dbl> 1,…
$ `Mother’s occupation` <dbl> 2,…
$ `Father’s occupation` <dbl> 5,…
$ `Weekly study hours` <dbl> 3,…
$ `Reading frequency...19` <dbl> 2,…
$ `Reading frequency...20` <dbl> 2,…
$ `Attendance to the seminars/conferences related to the department` <dbl> 1,…
$ `Impact of your projects/activities on your success` <dbl> 1,…
$ `Attendance to classes` <dbl> 1,…
$ `Preparation to midterm exams 1` <dbl> 1,…
$ `Preparation to midterm exams 2` <dbl> 1,…
$ `Taking notes in classes` <dbl> 3,…
$ `Listening in classes` <dbl> 2,…
$ `Discussion improves my interest and success in the course` <dbl> 1,…
$ `Flip-classroom` <dbl> 2,…
$ `Cumulative grade point average in the last semester (/4.00)` <dbl> 1,…
$ `Expected Cumulative grade point average in the graduation (/4.00)` <dbl> 1,…
$ `COURSE ID` <dbl> 1,…
$ GRADE <dbl> 1,…
2. Wrangle
First of all, the dataset is already cleaned without any missing value and contains only numeric values. There was no need to prepare data for predictive analysis using machine learning techniques. However, I selected 17 variables to practice the select function and renamed variables using the mutate function. For regression, it would make more sense when increasing the value in factors positively related to the outcome, so I recoded some variables(attsecon, attclass,flipclass) that possibly have negative relationships with the outcome variable, end-term grade.
# mutate variablesdata<- data %>%mutate(SID =`STUDENT ID`,stype =`Scholarship type`,Work =`Additional work`,Moed =`Mother’s education`,Faed =`Father’s education`,Mooc =`Mother’s occupation`,Faoc =`Father’s occupation`,sthr =`Weekly study hours`,attsecon =`Attendance to the seminars/conferences related to the department`,attclass =`Attendance to classes`,notetaking =`Taking notes in classes`,flipclass =`Flip-classroom`,CGPAlast =`Cumulative grade point average in the last semester (/4.00)`,CID =`COURSE ID` )
mutate: new variable 'SID' (character) with 145 unique values and 0% NA
new variable 'stype' (double) with 5 unique values and 0% NA
new variable 'Work' (double) with 2 unique values and 0% NA
new variable 'Moed' (double) with 6 unique values and 0% NA
new variable 'Faed' (double) with 6 unique values and 0% NA
new variable 'Mooc' (double) with 5 unique values and 0% NA
new variable 'Faoc' (double) with 5 unique values and 0% NA
new variable 'sthr' (double) with 5 unique values and 0% NA
new variable 'attsecon' (double) with 2 unique values and 0% NA
new variable 'attclass' (double) with 2 unique values and 0% NA
new variable 'notetaking' (double) with 3 unique values and 0% NA
new variable 'flipclass' (double) with 3 unique values and 0% NA
new variable 'CGPAlast' (double) with 5 unique values and 0% NA
new variable 'CID' (double) with 9 unique values and 0% NA
# converting the text (character) variables in the dataset into factorsdata <- data %>%mutate_if(is.character, as.factor)
mutate_if: converted 'SID' from character to factor (0 new NA)
3. Analyze
3.1 Prepare the train and test datasets
The machine learning technique was used to answer the research questions. Machine learning involves presenting a statistical model with a subset of data during training, teaching the model to make accurate predictions.
# set a seed to ensure the reproducibility of the data partition.set.seed(2023)# create a new object called trainIndex that will take 50 percent of the datatrainIndex <-createDataPartition(data$GRADE,p = .5, list =FALSE,times =1)
Then, add new variable to separate sub-datasets and set train subset and test subset using filter. And then remove the new variable, temp_id.
# add a new variable to the dataset, temporarily, to select rows according to their row numberdata <- data %>%mutate(temp_id =1:145)
mutate: new variable 'temp_id' (integer) with 145 unique values and 0% NA
# filter the dataset to get only the rows indicated by "trainIndex" vectordata_train <- data %>%filter(temp_id %in% trainIndex)
filter: removed 71 rows (49%), 74 rows remaining
# filter to make a testing subsetdata_test <- data %>%filter(!temp_id %in% trainIndex)
filter: removed 74 rows (51%), 71 rows remaining
# remove the temp_id from the datasetdata_test <- data_test %>%select(-temp_id)
select: dropped one variable (temp_id)
data_train <- data_train %>%select(-temp_id)
select: dropped one variable (temp_id)
3.2 Estimate the models using random forest modeling
All of the variables in the data frame except for the outcome, GRADE were used as predictors. For that, ‘GRADE ~.’ formulation was used. In addtion, the Random Forest modeling is used. Random Forest modeling extends decision tree modeling by simultaneously “growing” a collection of decision trees. Random forest is random in two ways, 1) each tree is restricted to “see” and split based on a limited subset of predictors, 2) a random subsample of the data is utilized for the growth of each individual tree, ensuring no single case is weighted too heavily in the final prediction.
# setting a seed for reproducibilityset.seed(2023)# run the modelrf_fit <-train(GRADE ~ .,data = data_train,method ="ranger")# summary of the model rf_fit
Random Forest
74 samples
15 predictors
No pre-processing
Resampling: Bootstrapped (25 reps)
Summary of sample sizes: 74, 74, 74, 74, 74, 74, ...
Resampling results across tuning parameters:
mtry splitrule RMSE Rsquared MAE
2 variance 2.212734 0.2630679 1.917325
2 extratrees 2.220720 0.2376902 1.926219
80 variance 1.461436 0.5916931 1.207956
80 extratrees 1.659308 0.5116768 1.376112
158 variance 1.384789 0.6219956 1.108802
158 extratrees 1.568199 0.5445477 1.271180
Tuning parameter 'min.node.size' was held constant at a value of 5
RMSE was used to select the optimal model using the smallest value.
The final values used for the model were mtry = 158, splitrule = variance
and min.node.size = 5.
From this step, train data set has 74 samples and provided the resampling results to select tuning parameter. The smallest Root Mean Square Error(RMSE) and the largest of the variance(Rsquared) indicate the best tuning parameter. It appears that model with the value of mtry equal to 158 can expect the result best. I checked the model one more time using different resampling technique to cross-validation to check the accuracy of the model.
##change the resampling technique to cross-validationset.seed(2023)train_control <-trainControl(method ="repeatedcv",number =10,repeats =10)rf_fit1 <-train(GRADE ~ .,data = data_train,method ="ranger",trControl = train_control)rf_fit1
Random Forest
74 samples
15 predictors
No pre-processing
Resampling: Cross-Validated (10 fold, repeated 10 times)
Summary of sample sizes: 67, 66, 68, 65, 66, 67, ...
Resampling results across tuning parameters:
mtry splitrule RMSE Rsquared MAE
2 variance 2.181029 0.3614700 1.913714
2 extratrees 2.187645 0.3374679 1.921027
80 variance 1.344958 0.6826343 1.120620
80 extratrees 1.510168 0.6172894 1.267233
158 variance 1.259087 0.7155164 1.015275
158 extratrees 1.423674 0.6370982 1.165012
Tuning parameter 'min.node.size' was held constant at a value of 5
RMSE was used to select the optimal model using the smallest value.
The final values used for the model were mtry = 158, splitrule = variance
and min.node.size = 5.
I could confirm the model with mtry = 158, the split rule was variance and the minimum node size = 5 is the best model.
However, I added another grid of values to test for mtry and min.node.size.
# Create a grid of different values of mtry, different splitrules, and different minimum node sizes to testtune_grid <-expand.grid(mtry =c(2, 41, 80, 121, 158),splitrule =c("variance", "extratrees"),min.node.size =c(1, 5, 10, 15, 20) )# Fit a new model, using the tuning grid rf_fit2 <-train(GRADE ~ .,data = data_train,method ="ranger",tuneGrid = tune_grid)rf_fit2
From the result, the model with the same values as identified before mtry = 158 and splirule=variance, but with min.node.size equal to 1 seems to fit best. Therefore, I selected the model as the final model named rf_fit2
#select the "finalModel" output from the rf_fit2 modelrf_fit2$finalModel
Ranger result
Call:
ranger::ranger(dependent.variable.name = ".outcome", data = x, mtry = min(param$mtry, ncol(x)), min.node.size = param$min.node.size, splitrule = as.character(param$splitrule), write.forest = TRUE, probability = classProbs, ...)
Type: Regression
Number of trees: 500
Sample size: 74
Number of independent variables: 158
Mtry: 158
Target node size: 1
Variable importance mode: none
Splitrule: variance
OOB prediction error (MSE): 1.603449
R squared (OOB): 0.6778552
3.3 Examining predictive accuracy on the test data set
To examine predictive accuracy, I put testing data through the model, and assigned the predicted values to a column called ‘pred’. In addition, I will make a column called ‘obs’ that has the real end term grade (GRADE). Then, I compared predicted and observed values to see how the model works.
# setting a seed for reproducibilityset.seed(2023)# Create a new object for the testing data including predicted values data_test_augmented <- data_test %>%mutate(pred =predict(rf_fit2, data_test),obs = GRADE)
mutate: new variable 'pred' (double) with 69 unique values and 0% NA
new variable 'obs' (double) with 8 unique values and 0% NA
# Transform this new object into a data framedefaultSummary(as.data.frame(data_test_augmented))
RMSE Rsquared MAE
1.6010290 0.4871063 1.2181972
Comparing the values to the ones I got from the training. The training data got RMSE = 1.448299, Rsquare = 0.5874383, MAE = 1.148431. The new values from the testing data are RMSE = 1.6010290, Rsquare = 0.4871063, MAE = 1. 2181972. The model performance was worse for the testing data as compared to the training data, because this testing data is new to the model, and the result is very similar, it can be interpret the model works greatly.
3.4 Variable importance
Random forest model has a very helpful characteristic which shows the importance of variables. I re-ran the ‘rf-fit2’ model with additional argument, importance.
# setting a seed for reproducibilityset.seed(2023)# Specify the same model as earlier with the addition of the variable importance metricrf_fit2_imp <-train( GRADE ~ .,data = data_train,method ="ranger",tuneGrid = tune_grid,importance ="permutation" )# Extract the variable importance from this new modelvarImp(rf_fit2_imp)
Finally, I got the ranked the order list of the variables answering the research question: which factors are most predictive of students’ performance. From the result above, course ID (CID), sex, comlative GPA in the last semester (CGPAlast) are the top 3 predictors for the end term grade.
3.5 Visualization
Now, this result can be visualized using the ‘ggplot’ function. The first 7 effective predictors are visualized only.
From the Machine Learning and Random Forest techniques, there are 7 factors that affect to the end term grade from the given dataset. Course ID was the most predictive variable because each course has a very different average of final grade. Sex, CGPA in the last semester and scholarship type were the next most important predictors. The course developers and professors can use this type of analysis to predict students who would struggle in the course or drop-out.
4.2 Suggestion of potential actions and limitation
This project has some limitation because the information about the background how to collect the data was limited. It was hard to interpret the results without deep understand of the dataset and the context. However, it was still meaningful for future real studies.
It would be interesting if I separate the variable into groups, such as personal questions, family questions, and study habit questions and see which group impact most on students’ performance.
Another aspect I can consider in the future with similar project is comparison with regression to see the effectiveness of machine learning.
Reference
Estrellado, R. A., Freer, E. A., Motsipak, J., Rosenberg, J. M., & Velásquez, I. C. (2020). Data science in education using R, chapter 14. London, England: Routledge. Nb. All authors contributed equally.
Namoun, A., & Alshanqiti, A. (2020). Predicting student performance using data mining and learning analytics techniques: A systematic literature review. Applied Sciences, 11(1), 237.
Rastrollo-Guerrero, J. L., Gómez-Pulido, J. A., & Durán-Domínguez, A. (2020). Analyzing and predicting students' performance by means of machine learning: A review. Applied sciences, 10(3), 1042.
Yılmaz, N., & Sekeroglu, B. (2019, August). Student performance classification using artificial intelligence techniques. In International Conference on Theory and Application of Soft Computing, Computing with Words and Perceptions (pp. 596-603). Cham: Springer International Publishing.