2017-02-20 13 views
0

私はKaggleの競技(link)のCTR予測モデルを開発しています。私はその後、さらに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,] 

で80/20で電車/テスト・セットにこれを分割し、その後、私はGLMモデル

を開発するad_trainデータを使用し、トレーニングセットからのデータの最初の100,000行に読みました
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) 

しかし、私はそれがad_testセットにしてどれだけチェックアウトする予測機能を使用しようとするたびに、私はエラーを取得:

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

できますか?新しいデータでGLMモデルをテストするにはどうすればよいですか?

EDIT:これは完全に機能します。

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.

関連する問題