빅데이터분석기사 실기책 254 실행이 안되어서요
왜 안되는지 모르겠어요.
이틀째 끙끙대다가 여쭙니다. 꼭 도와주세요.
library(dplyr)
library(lubridate)
library(caret)
library(recipes)
library(pROC)
setwd("C:/myR")
getwd()
X_train<-read.csv("X_train.csv",fileEncoding = "euc-kr")
X_train %>% glimpse
y_train<-read.csv("y_train.csv",fileEncoding = "euc-kr")
y_train %>% glimpse
x_test<-read.csv("x_test.csv",fileEncoding = "euc-kr")
x_test %>% glimpse
train<-left_join(X_train,y_train,by="cust_id") %>%
mutate(index="train")
train %>% glimpse
test<-x_test %>% mutate(index="test")
test %>% glimpse
full<-bind_rows(train ,test)
full %>% glimpse
table(full$index )
full$gender<-as.factor(full$gender)
full$index<-as.factor(full$index)
full %>% glimpse
# 한글변수 영문으로 바꿨음
x<-c(1:10)
y<-c(1:10)
kkk<-data.frame(x,y)
kkk %>% glimpse
kkk %>% rename(sssss=x)
data<-full %>%rename(total=총구매액,
max=최대구매액,
refund=환불금액,
product=주구매상품,
store=주구매지점,
day=내점일수,
count=내점당구매건수,
week=주말방문비율,
cycle=구매주기)
data %>% glimpse
colSums(is.na(data))
data$refund<-ifelse(is.na(data$refund),0,data$refund)
colSums(is.na(data))
rm=list(ls())
ls()
library(recipes)
recipe(gender~.,data=data) %>%
step_YeoJohnson(total,max,refund,day,count,week,cycle) %>%
step_scale(total,max,refund,day,count,week,cycle) %>%
step_center(total,max,refund,day,count,week,cycle) %>%
prep() %>% juice()->data1
data1 %>% glimpse
data1 %>% filter(index=='train') %>% select(-index)->traindata
traindata %>% glimpse
data1 %>% filter(index=='test')%>% select(-index)->testdata
testdata %>% glimpse
library(caret)
ctrl<-trainControl(method='cv', number=10,
summaryFunction=twoClassSummary,
classProbs=TRUE)
ctrl %>% glimpse
train(gender~., data=traindata,
method='rpart',
metric="ROC",
trControl=ctrl)->rpart1
# 위 실행하면 콘솔창에 아래와 같은 에러나옴
#Error: At least one of the class levels is not a valid R variable name; This will cause errors when class probabilities are generated because the variables names will be converted to X0, X1 . Please use factor levels that can be used as valid R variable names (see ?make.names for help).
댓글
안녕하세요.
이패스비즈 ADsP / 빅데이터분석기사 강사 김계철 입니다.
질의사항에 대한 답변드립니다.보내주신 문구는 목표변수(gender)가 팩터 변수가 아님을 알리는 오류 입니다.빅분기 실기 시험은 행단위로 실행되지 않고 전체가 실행이 됩니다.따라서 보내주신 스크립트를 몇개의 코딩 단위로 실행하면서 오류 부분을 확인하는 연습이 필요합니다.교재 및 강의 스크립트를 통해 한번 체크 부탁드리도록 할께요
참고로 이번 빅분기 실기 합격을 위한 강의를 준비하고 있습니다. 강의 내용이 완료가 되면 공지하도록 할께요.
감사합니다.
댓글을 남기려면 로그인하세요.