Skip to content

Instantly share code, notes, and snippets.

@mia-0032
Last active May 2, 2018 07:13
Show Gist options
  • Save mia-0032/9c0823303802cdcbd628da932e5017fe to your computer and use it in GitHub Desktop.
Save mia-0032/9c0823303802cdcbd628da932e5017fe to your computer and use it in GitHub Desktop.
MtGの対戦成績にロジスティック回帰をかけるスクリプト
library(readr)
library(dplyr)
library(rpart)
library(rpart.plot)
library(randomForest)
library(kernlab)
taisen <- read_csv(
"~/Downloads/taisen.csv",
col_types = cols(Date = col_date(format = "%Y/%m/%d"))
)
taisen$Game = sub('FNM', 'Casual Event', taisen$Game)
taisen$Game = as.factor(taisen$Game)
taisen$Deck = as.factor(taisen$Deck)
taisen$Match = as.factor(taisen$Match)
taisen$PassedDays = as.numeric(taisen$Date - min(taisen$Date))
taisen$PassedDaysLog = log(taisen$PassedDays + 1)
taisen$DeckUsingCountLog = log(taisen$DeckUsingCount)
taisen$Beginner = taisen$DeckUsingCount < 10
taisen_filtered=filter(taisen, Game != 'Queue')
#taisen_filtered=filter(taisen_filtered, Game != 'Casual Event')
#taisen_filtered=filter(taisen_filtered, Game != 'FNM')
# ロジスティック回帰(logit)
logi_result = glm(Y ~ Game + Deck + DeckUsingCountLog, taisen_filtered, family=binomial(link=logit))
summary(logi_result)
## オッズ比
exp(logi_result[[1]])
# ロジスティック回帰(probit)
logi_result = glm(Y ~ Game + Deck + DeckUsingCountLog, taisen_filtered, family=binomial(link=probit))
summary(logi_result)
## オッズ比
exp(logi_result[[1]])
# 決定木
tree_model = rpart(Match ~ Game + Deck + DeckUsingCount + PassedDays + PassedDaysLog + DeckUsingCountLog, data = taisen_filtered)
rpart.plot(tree_model)
# ランダムフォレスト
forest_model = randomForest(Match ~ Game + Deck + DeckUsingCount + PassedDays + PassedDaysLog + DeckUsingCountLog, data = taisen_filtered)
forest_model
importance(forest_model)
# SVM
svm = ksvm(Y ~ Game + Deck + DeckUsingCount + PassedDays, data = taisen_filtered)
svm
# 25回以上
over_25 = filter(taisen_filtered, DeckUsingCount >= 25)
summary(over_25)
under_25 = filter(taisen_filtered, DeckUsingCount < 25)
summary(under_25)
under_25.only = filter(under_25, Deck == 'MonoW Death&Taxes')
summary(under_25.only)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment