我正在对我拥有的数据集进行逻辑回归
model <- glm(feature1 ~ feature2, data=df, family="binomial")
但是glm
有什么意外的事情。它将“ feature2”的所有值作为变量,并在模型的logit参数中为其分配系数。
summary(model)的输出:
> summary(model)
Call:
glm(formula = feature1 ~ price, family = binomial(logit), data = df)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.22931 -0.00008 0.00008 0.82033 1.97277
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 6.931e-01 1.225e+00 0.566 0.571
price0.06 1.887e+01 1.075e+04 0.002 0.999
price0.1 -6.931e-01 1.871e+00 -0.371 0.711
price0.11 1.887e+01 1.075e+04 0.002 0.999
price0.2 1.887e+01 1.075e+04 0.002 0.999
price0.9 1.887e+01 1.075e+04 0.002 0.999
price0.99 1.092e-01 1.269e+00 0.086 0.931
price1 1.253e+00 1.626e+00 0.771 0.441
price1.01 1.887e+01 1.075e+04 0.002 0.999
price1.02 1.887e+01 1.075e+04 0.002 0.999
price1.04 1.887e+01 1.075e+04 0.002 0.999
> typeof(nonNPpriceDf$price)
[1] "integer"
我希望价格只是一个预测变量。我不明白为什么所有价格都被附加并视为变量。
这是typeof和class方法之间的混淆。factor2的类型为Integer,但类别为factor。我将factor2转换为数字,并且按预期工作正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句