[英]logistic regression for advertising analysis in R
我有一個數據集,用於測試7天的廣告時間是否比5天的廣告時間更好。 我認為邏輯回歸將是檢驗這一點的最佳方法。 我分別進行了2周的測試。 我有流量,注冊,損耗等數據。
數據如下所示:
5d 7d greater (does the 7d have atleast 5% more than 5d)
Traffic 179650 196395 1
subscribers 437899 442068 0
attrition 2304 2376 0
signups 5039 6246 1
1表示是,0表示否。
我在R中運行此代碼:
fit2<-glm(greater~X5d + X7d, data=logr2, family = "binomial")
然后
predict(fit2, data=logr2, type = "response")
我的輸出是:
1 2 3 4
1.000000e+00 6.753019e-13 1.386707e-10 1.000000e+00
要么
> round(predict(fit2, data=logr2, type = "response"))
1 2 3 4
1 0 0 1
如何運行它,以使我只得到1個輸出來告訴我1或0(即7天的總體增長率是否大於5%?)
謝謝
我認為您已經混淆了predict
函數的參數名稱(請參閱文檔 ),請嘗試以下操作:
predict(fit2, newdata=logr2, type = "response")
奇怪的輸出來自以下事實:您將訓練數據作為預測的輸入,這實際上沒有任何意義。 嘗試一些新的數據點,如下所示:
input = data.frame(X5d = 123, X7d = 22)
predict(fit2, newdata=logr2, type = "response")
結果:
1個
2.775557e-13
這意味着它是1
,幾率幾乎為0
。
如果您從數據集中給出確切點:
input = data.frame(X5d = 179650, X7d = 196395)
predict(fit2, newdata=input, type = "response")
結果:
1個
1個
因此,它是1
的概率為1
。
您可以從訓練集中檢查其他數據點-結果是完美的,因為對於這樣的訓練數據樣本,您的擬合是理想的。
您可以在此處找到一個簡單的類似示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.