当我尝试从 RI 中的模型中获取 PMML 代码时,出现以下错误:
Error in datypelist[[namelist[ndf2][[1]]]] : subscript out of bounds
这是给出错误的代码:
dim(train)
[1] 6963 31
model <- glm(trainLabels ~.,family=binomial(logit),data=train)
summary(model)
# export as PMML
library(pmml)
glm.pmml <- pmml(model)
Error in datypelist[[namelist[ndf2][[1]]]] : subscript out of bounds
这是没有给出任何错误的示例代码:
library(nnet)
library(pmml)
data(iris)
multinom = multinom(Species ~ Sepal.Length + Sepal.Width
+ Petal.Length + Petal.Width, data = iris)
pm<-pmml(multinom)
pm # returns an xml output in the console
我在哪里做错了?错误是由于数据大小引起的吗?请帮忙
更新:
在看了@Laterow 和@Tridi 的建议后,我想我应该看看火车组,我看到了一个字符向量,
str(train)
'data.frame': 6963 obs. of 31 variables:
$ YearOfBirth_Grouped : chr "3_1942-51" "4_1952-61" "7_ >=1982" "4_1952-61" ...
$ Avg_BMI_Transcript : num 26 21 22 26 28 30 30 25 21 20 ...
$ Avg_Temperature_Transcript : num 98.1 96.8 98.3 97.7 98.4 97.6 0 95 97 97.5 ...
$ Gender : Factor w/ 2 levels "F","M": 2 1 1 1 2 2 1 2 1 1 ...
$ trainLabels : int 1 0 0 0 0 0 0 0 0 0 ...
然后我将该字符向量转换为整数。然后 pmml 工作正常,
train$YearOfBirth_Grouped <- as.factor(train$YearOfBirth_Grouped)enter code here
str(train)
'data.frame': 6963 obs. of 31 variables:
$ YearOfBirth_Grouped : Factor w/ 7 levels "1_<=1931","2_1932-41",..: 3 4 7 4 7 6 7 3 3 4 ...
$ Avg_BMI_Transcript : num 26 21 22 26 28 30 30 25 21 20 ...
$ Avg_Temperature_Transcript : num 98.1 96.8 98.3 97.7 98.4 97.6 0 95 97 97.5 ...
$ Gender : Factor w/ 2 levels "F","M": 2 1 1 1 2 2 1 2 1 1 ...
$ trainLabels : int 1 0 0 0 0 0 0 0 0 0 ...