这里我的数据集是
pd
,我已将其分为训练和测试数据,如pd_train1
和pd_train2
sku national_inv lead_time in_transit_qty forecast_3_month forecast_6_month
1 3921548 8 12 0 0 0
2 3191009 83 2 33 157 377
3 2935810 8 4 0 0 0
4 2205847 31 4 63 70 160
5 4953497 3 12 0 0 0
6 2286884 0 8 0 0 0
forecast_9_month sales_1_month sales_3_month sales_6_month sales_9_month min_bank
1 0 1 1 2 5 2
2 603 44 98 148 156 53
3 0 0 0 1 1 0
4 223 27 90 164 219 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
potential_issue pieces_past_due perf_6_month_avg perf_12_month_avg local_bo_qty
1 0 0 0.63 0.75 0
2 0 0 0.68 0.66 0
3 0 0 0.73 0.78 0
4 0 0 0.73 0.78 0
5 0 0 0.81 0.74 0
6 0 0 0.91 0.96 0
deck_risk oe_constraint ppap_risk stop_auto_buy rev_stop went_on_backorder data
1 0 0 0 1 0 No train
2 0 0 0 1 0 No train
3 0 0 0 1 0 No train
4 0 0 1 1 0 No train
5 0 0 0 1 0 No train
6 0 0 0 1 0 No train
我想为我的训练数据创建一个 lm 模型
pd_train1
但我收到以下错误:
> fit=lm(went_on_backorder~.,data=pd_train1)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'y'
In addition: Warning message:
In storage.mode(v) <- "double" : NAs introduced by coercion
我尝试寻找无限值:
sapply(pd_train1, function(x) sum(is.infinite(x)))
sku national_inv lead_time in_transit_qty forecast_3_month
0 0 0 0 0
forecast_6_month forecast_9_month sales_1_month sales_3_month sales_6_month
0 0 0 0 0
sales_9_month min_bank potential_issue pieces_past_due perf_6_month_avg
0 0 0 0 0
perf_12_month_avg local_bo_qty deck_risk oe_constraint ppap_risk
0 0 0 0 0
stop_auto_buy rev_stop went_on_backorder data
0 0 0 0
还有我想要制作线性模型的训练数据中的 NA/NaN 值
sku national_inv lead_time in_transit_qty forecast_3_month
0 0 0 0 0
forecast_6_month forecast_9_month sales_1_month sales_3_month sales_6_month
0 0 0 0 0
sales_9_month min_bank potential_issue pieces_past_due perf_6_month_avg
0 0 0 0 0
perf_12_month_avg local_bo_qty deck_risk oe_constraint ppap_risk
0 0 0 0 0
stop_auto_buy rev_stop went_on_backorder
0 0 0
Inf %in% pd_train1$went_on_backorder
1] FALSE
NaN %in% pd_test$went_on_backorder
1] FALSE
从此以后我无法在数据集中获取 NA/NaN/Inf 值 有人可以帮我理解为什么会抛出错误吗? 这里
went_on_backorder
是我的目标变量。
went_on_backorder
列是一个因素。线性回归需要数字响应变量。
要使用逻辑回归,请在基础 R 中使用
glm
或诸如 vgam
之类的包。这是一个简短的例子:
pd_train1 <- data.frame('went_on_backorder' = c('No','Yes','Yes'), 'lead_time' = 1:3)
model <- glm(went_on_backorder ~ ., data = pd_train1, family = 'binomial')
您可以预测您的课程:
predict(model, newdata = data.frame('lead_time' = c(0,1,2.5,3.5)), type = "response")
我尝试使用两个 Anova 进行复制,并显示了此错误消息。 lm.fit(x, y, offset = offset, Single.ok = Single.ok, ...) 中的错误: 'y' 中的 NA/NaN/Inf 另外:警告消息: 处于存储模式(v) <- "double" : NAs introduced by coercion Please I need help to interpret this message