Created
February 7, 2019 03:36
-
-
Save FthrsAnalytics/c4bb5bbce7066cfa4c506cbc3410b9a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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