- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在论坛上进行了广泛的搜索,发现了很多类似的文章,但是没有一个能解决我的问题。
现在,我转向你了。
我有类似的数据:
ontime currency incoterms price month
1 USD FOB 234.2 01
1 CAD FOB 92.4 01
0 USD DAP 238.9 02
0 EUR FOB 100 03
1 CNY DAP 739.8 04
我这段代码:
g = df$ontime #binary
a = df$currency #String
b = df$INCOTERMS #String
c = df$price #float
f = df$month #string
mod1 <- glm(g~a+b+c,family=binomial(link="logit"), data=df[f=="01",])
pred_ontime1 <- predict(mod1,df[f%in%c("02","03","04"),],type="response")
我的愿望是测试我的模型,我使用 01 月、02 月、03 月和 04 月的数据进行训练。
我的结果是这样的:
Warning message:
'newdata' had 16623 rows but variables found have 22488 rows
我尝试过在 01 月进行训练,并在 01、02、03 和 04 月进行测试,这并没有给我错误消息,但是,对我的训练集中包含的数据进行测试似乎不合适。
值 16623 当然是 02、03 和 04 中的行数之和,而 22488 是 01、02、03 和 04 中的行数之和。
我能做什么?
最佳答案
尝试运行模型,而不先将每列保存到向量中。我认为 predict()
无法判断它与其建模的变量名称相同。
mod1 <- glm(ontime ~ currency + INCOTERMS + price, family = binomial(link = "logit"), data = df[df$month == "01",])
pred_ontime1 <- predict(mod1,df[df$month %in% c("02","03","04"),], type = "response")
看看是否有效。
<小时/>对于任何感兴趣的人来说,这是一个可重现的示例:
df <- read.table(textConnection("ontime currency incoterms price month
0 USD DAP 234.2 01
1 CAD FOB 92.4 01
0 USD DAP 238.9 02
0 USD FOB 100 03
1 CAD DAP 739.8 04"), header = TRUE)
mod1 <- glm(ontime ~ currency + incoterms + price, family = binomial(link = "logit"), data = df[df$month == 1,])
pred_ontime1 <- predict(mod1, df[df$month %in% c(2:4),], type = "response")
pred_ontime1
3 4 5
5.826215e-11 5.826215e-11 1.000000e+00
关于r - GLM:警告消息: 'newdata' 有 16623 行,但找到的变量有 22488 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50358471/
我在下面的 typescript 代码实现中遇到错误。我在这里将一种类型映射到另一种类型。但是 vscode 显示错误,即在分配之前使用了变量“newData”。我知道这可能是一个愚蠢的错误,但我找不
以下是 glmRob() 示例中的一些稍作修改的代码。当给定 newdata 参数时,predict.glmRob() 会出错。我做错了什么吗? suppressMessages(library(ro
有没有办法验证 newData 是否是 firebase 规则中的数组?像这样的东西: "node" : { ".validate" : "newData.isArray()" } 最佳答案 没有检测
嗨,我正在研究在LIME模型上使用R进行解释。当我运行此部分时,一切都很好。 # Library library(tm) library(SnowballC) library(caTools) lib
我的问题在于 predict() 函数、它的结构和绘制预测。 使用来 self 的模型的预测,我想可视化我的重要因素(及其相互作用)如何影响我的响应变量的概率。 我的模型: m1 <-glm ( m
我正在尝试将大型数据集 (>30Gb) 附加到现有的 pytables 表。表格为N列,数据集为N-1列;一列是在我知道其他 N-1 列之后计算的。 我正在使用 numpy.fromfile() 将数
我正在使用插入符包运行逻辑回归分析。 数据以 18x6 矩阵的形式输入 到目前为止,除了 predict() 函数之外,一切都很好。 R 告诉我 type 参数应该是 raw 或 prob 但 raw
我在论坛上进行了广泛的搜索,发现了很多类似的文章,但是没有一个能解决我的问题。 现在,我转向你了。 我有类似的数据: ontime currency incoterms price month 1
我想使用预测函数来预测 fjbjor 何时为 5.5,我总是收到此警告消息,我尝试了很多方法,但它总是会出现,所以有人可以看到我的内容吗?我在这里做错了 这是我的代码 fit.lm 看起来您真正想要
我正在尝试根据 svm 训练的模型来预测 A 值。这就是我的训练和测试数据的样子: A B C D r00 r01 r02 r03 ... ... ... ...
我在 R 中使用预测和 lm 函数时发现了特殊性。对于相同数据的数据帧和向量,我得到了不同的结果。 数据帧代码: data(mtcars) fitCar<-lm(mtcars$mpg~mtcars$w
我正在尝试从一篇论文中重新创建一个随机森林模型,但代码似乎不起作用,我只是刚刚学习 R,这超出了我的理解范围,但我会尽力解释。 论文的源代码可以在这里找到:[( https://journals.pl
我是 R 新手。我正在尝试使用 lda 对生成的网格中的所有点进行分类。训练集是使用 rmvnorm(n,mean,sigma) 随机生成的两个点组。这是我的代码:` # number of sam
我做了一个逻辑回归: EW <- glm(everwrk~age_p + r_maritl, data = NH11, family = "binomial") 此外,我想为 everwrk 的每个
我是一名优秀的程序员,十分优秀!