[英]logistic regression for advertising analysis in R
I have a data set where I am trying to test if having a 7 day advertising period is better than having a 5 day advertising period. 我有一个数据集,用于测试7天的广告时间是否比5天的广告时间更好。 I feel that logistic regression would be the best way to test this out.
我认为逻辑回归将是检验这一点的最佳方法。 I ran the tests for 2 weeks each.
我分别进行了2周的测试。 I have data like traffic, signups, attrition.
我有流量,注册,损耗等数据。
Here is what the data look like: 数据如下所示:
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 means yes and 0 means no. 1表示是,0表示否。
I ran this code in R: 我在R中运行此代码:
fit2<-glm(greater~X5d + X7d, data=logr2, family = "binomial")
then 然后
predict(fit2, data=logr2, type = "response")
My output is : 我的输出是:
1 2 3 4
1.000000e+00 6.753019e-13 1.386707e-10 1.000000e+00
or 要么
> round(predict(fit2, data=logr2, type = "response"))
1 2 3 4
1 0 0 1
How can I run it such that I get only 1 output to tell me 1 or 0 (IE does the 7 day have a greater than 5 % overall increase?) 如何运行它,以使我只得到1个输出来告诉我1或0(即7天的总体增长率是否大于5%?)
Thanks 谢谢
I think you've confused the argument names of the predict
function (see the documentation ), try this: 我认为您已经混淆了
predict
函数的参数名称(请参阅文档 ),请尝试以下操作:
predict(fit2, newdata=logr2, type = "response")
The strange output comes from the fact that you're giving the training data as the input to predict, which doesn't really make sense. 奇怪的输出来自以下事实:您将训练数据作为预测的输入,这实际上没有任何意义。 Try some fresh data point, like this:
尝试一些新的数据点,如下所示:
input = data.frame(X5d = 123, X7d = 22)
predict(fit2, newdata=logr2, type = "response")
Result: 结果:
1
1个
2.775557e-13
2.775557e-13
which means that it's 1
with probability almost 0
. 这意味着它是
1
,几率几乎为0
。
If you give an exact point from your data set: 如果您从数据集中给出确切点:
input = data.frame(X5d = 179650, X7d = 196395)
predict(fit2, newdata=input, type = "response")
Result: 结果:
1
1个
1
1个
So it's 1
with probability 1
. 因此,它是
1
的概率为1
。
You can check other data points from your training set - the results are perfect, as for such a few training data samples your fit is ideal. 您可以从训练集中检查其他数据点-结果是完美的,因为对于这样的训练数据样本,您的拟合是理想的。
You can find a simple, similar example here . 您可以在此处找到一个简单的类似示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.