2017-02-20 7 views
0

나는 Kaggle 경쟁 (link)에 대한 CTR 예측 모델을 개발 중입니다. 나는 훈련 세트에서 데이터의 첫 10 줄에 읽은 다음에, 또 다음R에서 로지스틱 회귀 모델을 테스트하는 방법?

ad_data <- read.csv("train", header = TRUE, stringsAsFactors = FALSE, nrows = 100000) 
trainIndex <- createDataPartition(ad_data$click, p=0.8, list=FALSE, times=1) 
ad_train <- ad_data[trainIndex,] 
ad_test <- ad_data[-trainIndex,] 

에 의해 20 분의 80에서 기차/테스트 세트로이 분할 나는 GLM 모델을 개발하기 위해 ad_train 데이터를 사용

무엇 제공

test_model <- predict(ad_glm_model, newdata = ad_test, type = "response") 
Warning message: 
'newdata' had 20000 rows but variables found have 80000 rows 

: 나는이 (가)는 ad_test 세트에 얼마나 잘하는지 확인하는 기능을 예측 사용하려고 할 때마다

ad_glm_model <- glm(ad_train$clicks ~ ad_train$C1 + ad_train$site_category + ad_train$device_type, family = binomial(link = "logit"), data = ad_train) 

는하지만, 나는 오류가? 새 데이터에서 내 GLM 모델을 테스트하려면 어떻게합니까?

편집 : 완벽하게 작동합니다.

ad_glm_model <- glm(clicks ~ C1 + site_category + device_type, family = binomial(link = "logit"), data = ad_train) 
+1

는 GLM 호출에서'ad_train을 $'사용하지 말아, 단지 대신'='데이터를 사용 – user20650

답변

0

이것은 모델 수식의 각 변수에 대한 데이터 프레임의 이름을 포함하기 때문에 발생합니다. 대신, 수식은 다음과 같아야합니다 중복 통지에 second link에서 설명한 바와 같이

glm(clicks ~ C1 + site_category + device_type, family = binomial(link = "logit"), data = ad_train) 

:

This is a problem of using different names between your data and your newdata and not a problem between using vectors or dataframes.

When you fit a model with the lm function and then use predict to make predictions, predict tries to find the same names on your newdata. In your first case name x conflicts with mtcars$wt and hence you get the warning.