Skip to content

Instantly share code, notes, and snippets.

@FthrsAnalytics
Created February 7, 2019 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FthrsAnalytics/c4bb5bbce7066cfa4c506cbc3410b9a4 to your computer and use it in GitHub Desktop.
Save FthrsAnalytics/c4bb5bbce7066cfa4c506cbc3410b9a4 to your computer and use it in GitHub Desktop.
##Load Packages needed to run the R code
library(readxl)
library(tidyverse)
##Import Data
file_path <- ##"file path of the source Excel file/Predictive Analytics with R in Power BI.xlsx"
data_set <- read_excel(file_path) %>%
select(id, total_points, now_cost, selected_by_percent, minutes, goals_scored, assists, clean_sheets, pos)
data_set$pos <- factor(data_set$pos, levels = c("GKP", "DEF", "MID", "FWD"), ordered = TRUE)
##Manipulate Data
model_data <- data_set %>%
filter(minutes > 180) %>%
mutate(points_per_90 = total_points / minutes * 90) %>%
select(-minutes, -total_points)
##Create Clusters
set.seed(237)
fantasy_clusters <- kmeans(model_data[,2:6,8], 3)
model_data$cluster <- as.factor(fantasy_clusters$cluster)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment