Due to recent updates, all users are required to create an Altair One account to login to the RapidMiner community. Click the Register button to create your account using the same email that you have previously used to login to the RapidMiner community. This will ensure that any previously created content will be synced to your Altair One account. Once you login, you will be asked to provide a username that identifies you to other Community users. Email us at Community with questions.
Multilogit in R - Model Application fails
Thomas_Ott
RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn
Alright guys, I'm running into an error using R. I'm attaching a sample process, I can't post the actual data but it's similar to the data below.
I'm using the Mlogit package in R and I can build a model just fine. When I try to apply the model to new data, I get an application error (see screenshot below). There is a predict function in the package but I'm wondering if I need to fit the model first in the Apply stage? I was under impression that I don't need to.
<?xml version="1.0" encoding="UTF-8"?><process version="8.1.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="8.1.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data" compatibility="8.1.001" expanded="true" height="68" name="Generate Data" width="90" x="45" y="34">
<parameter key="target_function" value="random classification"/>
</operator>
<operator activated="true" class="generate_id" compatibility="8.1.001" expanded="true" height="82" name="Generate ID" width="90" x="179" y="34"/>
<operator activated="true" class="split_data" compatibility="8.1.001" expanded="true" height="103" name="Split Data" width="90" x="246" y="187">
<enumeration key="partitions">
<parameter key="ratio" value="0.7"/>
<parameter key="ratio" value="0.3"/>
</enumeration>
</operator>
<operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="82" name="Execute Mlogit Model" width="90" x="447" y="34">
<parameter key="script" value="library(mlogit) rm_main = function(data) { 	# print the meta data 	print(metaData) 	# access the meta data for every entry 	for(i in seq(along=metaData$data)) { 	print(paste("type of", names(metaData$data)[i], "in the original example set:", metaData$data[[i]]$type)) 	print(paste("role of", names(metaData$data)[i], "in the original example set:", metaData$data[[i]]$role)) } 	data$id <- as.factor(data$id) 	data$label <- as.logical(data$label) 	 	mModel <- mlogit.data(formula = label, data = data, alt.var="id", shape= "long") 	 	return(mModel) } "/>
</operator>
<operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="103" name="Apply Mlogit Model" width="90" x="648" y="187">
<parameter key="script" value="library(mlogit) rm_main = function(mModel, data) {		 	# print the meta data 	print(metaData) 	# access the meta data for every entry 	for(i in seq(along=metaData$data)) { 	print(paste("type of", names(metaData$data)[i], "in the original example set:", metaData$data[[i]]$type)) 	print(paste("role of", names(metaData$data)[i], "in the original example set:", metaData$data[[i]]$role)) } 	data$id <- as.factor(data$id) 	 	newM <- mlogit.data(data, alt.var="id", shape ="long") 	 	result <-predict(mModel,newdata=newM) 	#result <- predict(mModel, data) 	data$prediction <- result 	 	metaData$data$prediction <<- list(type="real", role="prediction") 	 	return(data) 	 }"/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Generate ID" to_port="example set input"/>
<connect from_op="Generate ID" from_port="example set output" to_op="Split Data" to_port="example set"/>
<connect from_op="Split Data" from_port="partition 1" to_op="Execute Mlogit Model" to_port="input 1"/>
<connect from_op="Split Data" from_port="partition 2" to_op="Apply Mlogit Model" to_port="input 2"/>
<connect from_op="Execute Mlogit Model" from_port="output 1" to_op="Apply Mlogit Model" to_port="input 1"/>
<connect from_op="Apply Mlogit Model" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
Thoughts on this? Maybe R experts @yyhuang and @Telcontar120 have a clue?
Tagged:
0
Answers
Hi Tom,
you picked my curiosity and I've read the vignette on the mlogit package:
Therefore mlogit.data returns a data frame, not a model.
Regards,
Sebastian
@SGolbert ah, i see. So when I change mlogit.data to just mlogit I get an "object 'label'" not found. I might have to convert the binominal to an integer.