>RE::VISION CRM

R 데이터 분석

[SKK_DA1] predictive modeling practice

YONG_X 2017. 5. 25. 09:24

# use HR defection data


hr01 <- read.csv("https://t1.daumcdn.net/cfile/blog/23402B3B591A45D631?download")

 

로지스틱회귀분석 모델링

의사결정나무 모델링

군집분석 - k-Means ; hclust

 

hr01 <- read.csv

("https://t1.daumcdn.net/cfile/blog/23402B3B591A?download

313F65")

names(hr01)

#로지스틱회귀분석 모델링

lm4 <- glm(left~., family=binomial(link='logit'),

data=hr01)
summary(lm4)


#의사결정나무 모델링
require(party)
library(party)


t1 <- ctree(left~., data=hr01, controls =

ctree_control(maxdepth = 3, minbucket=300))
plot(t1)


#군집분석 - k-Means ; hclust
s2 <- hr01[,c("satisfaction_level",

"last_evaluation")]
fit <- kmeans(s2, 3)
table(fit$cluster)
plot(hr01$satisfaction_level, hr01$last_evaluation,

col=fit$cluster)

hc01 <- hclust(dist(s2))
# Error ! 건수가 많아서





# mtcars로

선형회귀분석 모델링

다중선형회귀분석 모델링

의사결정나무 모델링

파티셔닝

모델평가 ROC 챠트 작성

군집분석 - k-Means ; hclust


#========

# mtcars로
data(mtcars)

선형회귀분석 모델링
lm1 <- lm(mpg~., data=mtcars)
summary(lm1)

다중선형회귀분석 모델링
lm2 <- lm(mpg~., data=mtcars)
summary(lm2)
plot(lm2)

의사결정나무 모델링
t1 <- ctree(mpg~., data=mtcars, controls =

ctree_control(maxdepth = 3, minbucket=3))
plot(t1)


파티셔닝
set.seed(123)
smp <- sample(1:nrow(mtcars), round(nrow(mtcars)/2))
mtcars_train <- mtcars[smp, ]
mtcars_test <- mtcars[row.names(mtcars)[-smp], ]

모델평가 ROC 챠트 작성
t1 <- ctree(mpg~., data=mtcars_train, controls =

ctree_control(maxdepth = 3, minbucket=3))
plot(t1)

# ROC는 해당사항 없음

군집분석 - k-Means ; hclust
s2 <- mtcars[,c("wt", "hp", "gear")]
fit <- kmeans(s2, 3)
table(fit$cluster)
plot(mtcars$wt, mtcars$hp, col=fit$cluster, pch=19 )
text(mtcars$wt, mtcars$hp, labels=row.names(mtcars),

pos=3)

plot(hclust(dist(s2)))