简体   繁体   English

将R模型转换为pmml时出错

[英]Error while converting R models to pmml

When I try to get the PMML code out of my models in RI get the following error: 当我尝试从RI中的模型中获取PMML代码时,出现以下错误:

Error in datypelist[[namelist[ndf2][[1]]]] : subscript out of bounds

Here is the code which gives error: 这是给出错误的代码:

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

Here is the sample code that doesn't give any error: 这是不给出任何错误的示例代码:

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

Where am I doing it wrong? 我在哪里做错了? Is the error caused due to the data size? 错误是由于数据大小引起的吗? Please help 请帮忙

UPDATE: 更新:

After watching @Laterow and @Tridi suggestions I thought I should look at the train set and I see a character vector in it, 看完@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 ...

Then I converted that character vector into integer. 然后,我将该字符向量转换为整数。 Then pmml worked fine, 然后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 ...

Yes, I have encountered the same error message in conversion of R script for a predictive model which includes also text mining code - to PMML . 是的,在用于预测模型的R脚本转换中,我也遇到了相同的错误消息,该模型还包括文本挖掘代码-到PMML

I have solved the problem by conversion of my "characters" features to factors (by factorization of characters). 我已经通过将“字符”特征转换为因子(通过字符分解)解决了该问题。 It worked, the PMML error disappeared and I was able to generate the PMML successfully. 它有效, PMML错误消失了,我能够成功生成PMML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM