The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
How to use Model built in RapidMiner (GUI) in JAVA Application
Hello,
I want to write a java program that gets input data and uses a model, which was built with RapidMiner, to produce an output.
I have this code:
My process file: (it is a simple process, a Retrieve- and Read-CSV-file-Operator and one Apply-Model-Operator)
I want to write a java program that gets input data and uses a model, which was built with RapidMiner, to produce an output.
I have this code:
Caused by: com.rapidminer.operator.UserError: Cannot retrieve repository data from entry '//repository/models/cross_validation_model_neural_net9'. Reason: Cannot load data from 'C:\Users\wahl\price-calculator\src\main\resources\repository\models\cross_validation_model_neural_net9.ioo': java.lang.ClassCastException: cannot assign instance of java.util.ArrayList to field com.rapidminer.example.table.AbstractAttribute.transformations of type java.util.LinkedList in instance of com.rapidminer.example.table.NumericalAttribute. at com.rapidminer.Process.loadInitialData(Process.java:761) at com.rapidminer.Process.run(Process.java:933) at com.rapidminer.Process.run(Process.java:873) at com.rapidminer.Process.run(Process.java:832) at com.rapidminer.Process.run(Process.java:827) at com.rapidminer.Process.run(Process.java:817) at net.infosim.dilink.Calculator.calculatePrice(Calculator.java:79) at net.infosim.dilink.PriceCalculatorService.calculate(PriceCalculatorService.java:29) at net.infosim.dilink.PriceCalculatorService_ClientProxy.calculate(PriceCalculatorService_ClientProxy.zig:186) at net.infosim.dilink.PriceCalculatorResource.performCalculate(PriceCalculatorResource.java:46) at net.infosim.dilink.PriceCalculatorResource_ClientProxy.performCalculate(PriceCalculatorResource_ClientProxy.zig:186) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130) at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:621) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:487) at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:437) at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:362) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:439) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:400) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:374) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:67) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488) ... 20 more Caused by: com.rapidminer.repository.RepositoryException: Cannot load data from 'C:\Users\wahl\price-calculator\src\main\resources\repository\models\cross_validation_model_neural_net9.ioo': java.lang.ClassCastException: cannot assign instance of java.util.ArrayList to field com.rapidminer.example.table.AbstractAttribute.transformations of type java.util.LinkedList in instance of com.rapidminer.example.table.NumericalAttribute at com.rapidminer.repository.local.SimpleIOObjectEntry.retrieveData(SimpleIOObjectEntry.java:91) at com.rapidminer.Process.loadInitialData(Process.java:752) ... 45 more Caused by: java.lang.ClassCastException: cannot assign instance of java.util.ArrayList to field com.rapidminer.example.table.AbstractAttribute.transformations of type java.util.LinkedList in instance of com.rapidminer.example.table.NumericalAttribute at java.base/java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2281) at java.base/java.io.ObjectStreamClass$FieldReflector.checkObjectFieldValueTypes(ObjectStreamClass.java:2244) at java.base/java.io.ObjectStreamClass.checkObjFieldValueTypes(ObjectStreamClass.java:1463) at java.base/java.io.ObjectInputStream.defaultCheckFieldValues(ObjectInputStream.java:2536) at java.base/java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:655) at com.rapidminer.example.table.AbstractAttribute.readObject(AbstractAttribute.java:114) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at java.base/java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1216) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2381) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2520) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2414) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:517) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:475) at java.base/java.util.ArrayList.readObject(ArrayList.java:899) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at java.base/java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1216) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2381) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2520) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2414) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2520) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2414) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2520) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2414) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2520) at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2414) at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2215) at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1707) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:517) at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:475) at com.rapidminer.operator.tools.JavaBinaryBodySerializer.deserialize(SerializationType.java:46) at com.rapidminer.operator.tools.IOObjectSerializer.deserialize(IOObjectSerializer.java:105) at com.rapidminer.repository.local.SimpleIOObjectEntry.retrieveData(SimpleIOObjectEntry.java:89) ... 46 more</code><pre>public String calculatePrice(Material materialToMatch) throws OperatorException, RepositoryException, IOException, XMLException {<br> RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);<br> URL path = Calculator.class.getClassLoader().getResource("repository");<br> System.setProperty("rapidminer.home", path.toString());<br> RapidMiner.init();<br><br> RepositoryManager repositoryManager = RepositoryManager.getInstance(null);<br><br> String absolutePath = null;<br> if (repositoryManager.getRepositories().get(2) instanceof LocalRepository) {<br> LocalRepository localRepository = (LocalRepository) repositoryManager.getRepositories().get(2);<br> File location = localRepository.getFile();<br> absolutePath = location.getAbsolutePath().replace("\\", "/");<br> } <br> assert absolutePath != null;<br> RepositoryLocation pLoc = new RepositoryLocation("//Repository/processes/model_neuralnet");<br> ProcessEntry pEntry = (ProcessEntry) pLoc.locateEntry();<br> String processXML = pEntry.retrieveXML();<br> Process process = new Process(processXML);<br> process.setProcessLocation(new RepositoryProcessLocation(pLoc));<br><br> Operator read_csv = process.getOperator("Read CSV");<br> read_csv.setParameter(PARAMETER_CSV_FILE, absolutePath + "/data/input.csv");<br> Operator retrieve = process.getOperator("Retrieve");<br> retrieve.setParameter(PARAMETER_REPOSITORY_ENTRY, "/models/cross_validation_model_neural_net9");<br><br> IOContainer ioResult = process.run();<br><br> ExampleSet resultSet = null;<br> if (ioResult.getElementAt(0) instanceof ExampleSet) {<br> resultSet = (ExampleSet) ioResult.getElementAt(0);<br> }<br> if (resultSet == null) {<br> throw new IllegalArgumentException("Error while calculating the price");<br> }<br> return resultSet.toString();<br> }</pre></pre></pre>My repository-folder is structured like this:<br>repository <br> -data<br> -input.csv<br> -models<br> -cross_validation_model_neural_net9.ioo<br> -processes<br> -model_neuralnet.rmp<br><br>I built the model and process file with the RapidMiner GUI. Then, I copied the files and pasted them into my java-project. This leads to following error:<br><br><pre class="CodeBlock"><code>
My process file: (it is a simple process, a Retrieve- and Read-CSV-file-Operator and one Apply-Model-Operator)
<?xml version="1.0" encoding="UTF-8"?><process version="9.7.002">
<context>
<input>
<location>//Repository/models/cross_validation_model_neural_net9</location>
</input>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="9.7.002" expanded="true" name="Process">
<parameter key="logverbosity" value="init"/>
<parameter key="random_seed" value="2001"/>
<parameter key="send_mail" value="never"/>
<parameter key="notification_email" value=""/>
<parameter key="process_duration_for_mail" value="30"/>
<parameter key="encoding" value="SYSTEM"/>
<process expanded="true">
<operator activated="true" class="read_csv" compatibility="9.7.002" expanded="true" height="68" name="Read CSV" width="90" x="112" y="136">
<parameter key="csv_file" value="//Repository/data/input.csv"/>
<parameter key="column_separators" value=";"/>
<parameter key="trim_lines" value="false"/>
<parameter key="use_quotes" value="true"/>
<parameter key="quotes_character" value="""/>
<parameter key="escape_character" value="\"/>
<parameter key="skip_comments" value="false"/>
<parameter key="comment_characters" value="#"/>
<parameter key="starting_row" value="1"/>
<parameter key="parse_numbers" value="true"/>
<parameter key="decimal_character" value="."/>
<parameter key="grouped_digits" value="false"/>
<parameter key="grouping_character" value=","/>
<parameter key="infinity_representation" value=""/>
<parameter key="date_format" value=""/>
<parameter key="first_row_as_names" value="true"/>
<list key="annotations"/>
<parameter key="time_zone" value="SYSTEM"/>
<parameter key="locale" value="English (United States)"/>
<parameter key="encoding" value="SYSTEM"/>
<parameter key="read_all_values_as_polynominal" value="false"/>
<list key="data_set_meta_data_information"/>
<parameter key="read_not_matching_values_as_missings" value="true"/>
<parameter key="datamanagement" value="double_array"/>
<parameter key="data_management" value="auto"/>
</operator>
<operator activated="true" class="retrieve" compatibility="9.7.002" expanded="true" height="68" name="Retrieve" width="90" x="112" y="34">
<parameter key="repository_entry" value="//Repository/models/cross_validation_model_neural_net9.ioo"/>
</operator>
<operator activated="true" class="apply_model" compatibility="9.7.002" expanded="true" height="82" name="Apply Model" width="90" x="447" y="34">
<list key="application_parameters"/>
<parameter key="create_view" value="false"/>
</operator>
<connect from_op="Read CSV" from_port="output" to_op="Apply Model" to_port="unlabelled data"/>
<connect from_op="Retrieve" from_port="output" to_op="Apply Model" to_port="model"/>
<connect from_op="Apply Model" from_port="labelled data" 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>
Tagged:
0
Answers
I still can't get any output due to this error:
Dortmund, Germany