library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(stats)

Introduction

Learning analytics is the use of data to understand and improve learning. Unsupervised learning is a type of machine learning that can be used to identify patterns and relationships in data without the need for labeled data.

In this case study, you will use unsupervised learning to analyze learning data from a Simulated School course. You will use dimensionality reduction to reduce the number of features in the data, and then use clustering to identify groups of students with similar learning patterns.

Data

The data for this case study is generated with the simulated function below. The data contains the following features:

Student ID: A unique identifier for each student Feature 1: A measure of student engagement Feature 2: A measure of student performance

simulate_student_features <- function(n = 100) {
  # Set the random seed
  set.seed(260923)
  
  # Generate unique student IDs
  student_ids <- seq(1, n)

  # Simulate student engagement
  student_engagement <- rnorm(n, mean = 50, sd = 10)

  # Simulate student performance
  student_performance <- rnorm(n, mean = 60, sd = 15)

  # Combine the data into a data frame
  student_features <- data.frame(
    student_id = student_ids,
    student_engagement = student_engagement,
    student_performance = student_performance
  )

  # Return the data frame
  return(student_features)
}

This function takes the number of students to simulate as an input and returns a data frame with three columns: student_id, student_engagement, and student_performance. The student_engagement and student_performance features are simulated using normal distributions with mean values of 50 and 60, respectively, and standard deviations of 10 and 15, respectively.

To use the simulate_student_features() function, we can simply pass the desired number of students to simulate as the argument:

student_features <- simulate_student_features(n = 100)

We can then use this data frame to perform unsupervised learning to identify groups of students with similar learning patterns,

Tasks

Simulate the data.

Simulating the data occurred in the previous chunk.

Perform dimensionality reduction on the data using PCA.

scaled_data <- scale(student_features[, c("student_engagement", "student_performance")])

pr.out <- prcomp(scaled_data, center = TRUE, scale. = TRUE)

summary(pr.out)
## Importance of components:
##                           PC1    PC2
## Standard deviation     1.0104 0.9895
## Proportion of Variance 0.5104 0.4896
## Cumulative Proportion  0.5104 1.0000
biplot(pr.out)

pr.var <- pr.out$sdev^2

pve <- pr.var/sum(pr.var)

plot(pve, xlab = "Principal Component",
     ylab = "Proportion of Variance Explained",
     ylim = c(0, 1), type = "b")

plot(cumsum(pve), xlab = "Principal Component",
     ylab = "Cumulative Proportion of Variance Explained",
     ylim = c(0, 1), type = "b")

Cluster the data using KMeans and other clustering algorithms.

k <- 4

km.out <-kmeans(scaled_data, centers = k, nstart = 20)
plot(scaled_data[, c("student_engagement", "student_performance")],
     col = km.out$cluster,
     main = paste("k-means clustering of students", k, "clusters"),
     xlab = "Student Engagement", ylab = "Student Performance")

Cluster data using hierarchical

hclust.out <- hclust(dist(scaled_data), method = "average")

plot(hclust.out, main = "Hierarchical")

Interpret the results of your analysis.

library(cluster)

pam_kmstudent <- pam(scaled_data, k=3)

plot(silhouette(pam_kmstudent))

library(cluster)

pam_kmstudent <- pam(scaled_data, k=4)

plot(silhouette(pam_kmstudent))

library(cluster)

pam_kmstudent <- pam(scaled_data, k=5)

plot(silhouette(pam_kmstudent))

Submission

Submit a report containing the following:

Your report should include your code. Submit the published RPubs link to Blackboard.