RapidMiner

Contributor II ArmMiner
Contributor II

How to use a trained classification model of RapidMIner in my Java application?

Hi all,

I would like to know some opinions or hints how to solve an implementation problem. I want to use a text classification model to classify the test data in my java application, so that I would just give the path for test file and the application would give the classified test data as an output. Any idea?
Thanks!

18 REPLIES
RM Staff
RM Staff

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

you can build the process in RapidMiner so that it classifies your data as you want, and then use said process via java as described here.
You can alter the parameter pointing to the file easily before each process execution, see question 6) in the link I provided above.

Regards,
Marco
_________________________________________________________
Team Lead Software Engineering | RapidMiner GmbH
Contributor II ArmMiner
Contributor II

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

thanks for the reply!
I've downloaded the RapidMIner_Unuk through SVN, but I have 28 errors. Compiler Compliance Level is 1.6. Is this the reason?
The part of errors are the following:

Description                                    Resource                                          Path                                                Location        Type
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 150 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 154 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 159 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 212 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 215 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 242 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 243 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 246 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 249 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 135 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 136 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 141 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 146 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 196 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 232 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 341 Java Problem
tableList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 342 Java Problem
The method getParentLogger() is undefined for the type Driver DriverAdapter.java /RapidMiner_Unuk/src/com/rapidminer/tools/jdbc line 111 Java Problem
The method getParentLogger() of type DriverAdapter must override or implement a supertype method DriverAdapter.java /RapidMiner_Unuk/src/com/rapidminer/tools/jdbc line 110 Java Problem
The method setShape(Shape) is undefined for the type BubbleWindow BubbleWindow.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/components line 380 Java Problem
The method setShape(Shape) is undefined for the type new ComponentAdapter(){} BubbleWindow.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/components line 229 Java Problem
The type DefaultListModel is not generic; it cannot be parameterized with arguments <ColumnIdentifier> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 76 Java Problem
The type DefaultListModel is not generic; it cannot be parameterized with arguments <TableName> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 73 Java Problem
The type JList is not generic; it cannot be parameterized with arguments <ColumnIdentifier> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 76 Java Problem
The type JList is not generic; it cannot be parameterized with arguments <ColumnIdentifier> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 76 Java Problem
The type JList is not generic; it cannot be parameterized with arguments <TableName> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 73 Java Problem
The type JList is not generic; it cannot be parameterized with arguments <TableName> SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 73 Java Problem
attributeList cannot be resolved SQLQueryBuilder.java /RapidMiner_Unuk/src/com/rapidminer/gui/tools/dialogs line 248 Java Problem
ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized Tested.java /Group/src line 23 Java Problem
HashSet is a raw type. References to generic type HashSet<E> should be parameterized Tested.java /Group/src line 79 Java Problem
Null comparison always yields false: The variable colorValues cannot be null at this location StackedBarChartPlotter.java /RapidMiner_Unuk/src/com/rapidminer/gui/plotter/charts line 510 Java Problem
Null comparison always yields false: The variable currentStateXML cannot be null at this location MainFrame.java /RapidMiner_Unuk/src/com/rapidminer/gui line 1229 Java Problem
Null comparison always yields false: The variable dataTable cannot be null at this location ColorSchemeDialog.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/gui line 1082 Java Problem
Null comparison always yields false: The variable inputStream cannot be null at this location RemoteRepository.java /RapidMiner_Unuk/src/com/rapidminer/repository/remote line 463 Java Problem
Null comparison always yields false: The variable titleText cannot be null at this location GlobalConfigurationPanel.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/gui line 130 Java Problem
Potential null pointer access: The variable allWeights may be null at this location MedianAggregator.java /RapidMiner_Unuk/src/com/rapidminer/operator/preprocessing/transformation/aggregation line 150 Java Problem
Potential null pointer access: The variable allWeights may be null at this location MedianAggregator.java /RapidMiner_Unuk/src/com/rapidminer/operator/preprocessing/transformation/aggregation line 153 Java Problem
Potential null pointer access: The variable allWeights may be null at this location MedianAggregator.java /RapidMiner_Unuk/src/com/rapidminer/operator/preprocessing/transformation/aggregation line 155 Java Problem
Potential null pointer access: The variable allWeights may be null at this location MedianAggregator.java /RapidMiner_Unuk/src/com/rapidminer/operator/preprocessing/transformation/aggregation line 184 Java Problem
Potential null pointer access: The variable b64os may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 733 Java Problem
Potential null pointer access: The variable b64os may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1006 Java Problem
Potential null pointer access: The variable bais may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1369 Java Problem
Potential null pointer access: The variable bais may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1464 Java Problem
Potential null pointer access: The variable baos may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 737 Java Problem
Potential null pointer access: The variable baos may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1010 Java Problem
Potential null pointer access: The variable baos may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1361 Java Problem
Potential null pointer access: The variable bestAssignmentKernel may be null at this location GreedyKernelDistribution.java /RapidMiner_Unuk/src/com/rapidminer/tools/math/distribution/kernel line 97 Java Problem
Potential null pointer access: The variable bestAssignments may be null at this location FastKMeans.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 296 Java Problem
Potential null pointer access: The variable bestAssignments may be null at this location KMeans.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 208 Java Problem
Potential null pointer access: The variable bestAssignments may be null at this location KMedoids.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 215 Java Problem
Potential null pointer access: The variable bestEver may be null at this location EvolutionaryFeatureAggregation.java /RapidMiner_Unuk/src/com/rapidminer/operator/features/aggregation line 240 Java Problem
Potential null pointer access: The variable bestMergeKernel1 may be null at this location GreedyKernelDistribution.java /RapidMiner_Unuk/src/com/rapidminer/tools/math/distribution/kernel line 99 Java Problem
Potential null pointer access: The variable bestModel may be null at this location FastKMeans.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 288 Java Problem
Potential null pointer access: The variable bestModel may be null at this location KMeans.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 192 Java Problem
Potential null pointer access: The variable bestModel may be null at this location KMedoids.java /RapidMiner_Unuk/src/com/rapidminer/operator/clustering/clusterer line 207 Java Problem
Potential null pointer access: The variable bestNode may be null at this location BallTree.java /RapidMiner_Unuk/src/com/rapidminer/tools/math/container line 126 Java Problem
Potential null pointer access: The variable bestNode may be null at this location BallTree.java /RapidMiner_Unuk/src/com/rapidminer/tools/math/container line 129 Java Problem
Potential null pointer access: The variable bestPerformance may be null at this location RandomOptimizationChain.java /RapidMiner_Unuk/src/com/rapidminer/operator/meta line 122 Java Problem
Potential null pointer access: The variable bis may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1608 Java Problem
Potential null pointer access: The variable bis may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1676 Java Problem
Potential null pointer access: The variable bos may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1512 Java Problem
Potential null pointer access: The variable bos may be null at this location Base64.java /RapidMiner_Unuk/src/com/rapidminer/io line 1549 Java Problem
Potential null pointer access: The variable c1 may be null at this location AbstractTableModelTableRenderer.java /RapidMiner_Unuk/src/com/rapidminer/gui/renderer line 167 Java Problem
Potential null pointer access: The variable c2 may be null at this location AbstractTableModelTableRenderer.java /RapidMiner_Unuk/src/com/rapidminer/gui/renderer line 169 Java Problem
Potential null pointer access: The variable changeDimensionConfig may be null at this location PlotData.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/data line 348 Java Problem
Potential null pointer access: The variable changeDimensionConfig may be null at this location PlotData.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/data line 356 Java Problem
Potential null pointer access: The variable changeRangeAxis may be null at this location PlotData.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/data line 377 Java Problem
Potential null pointer access: The variable changeValueSource may be null at this location PlotData.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/data line 445 Java Problem
Potential null pointer access: The variable changeValueSource may be null at this location PlotData.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/data line 465 Java Problem
Potential null pointer access: The variable cluster may be null at this location GaussianMixtureFunction.java /RapidMiner_Unuk/src/com/rapidminer/operator/generator line 101 Java Problem
Potential null pointer access: The variable cluster may be null at this location TwoGaussiansClassificationFunction.java /RapidMiner_Unuk/src/com/rapidminer/operator/generator line 98 Java Problem
Potential null pointer access: The variable confidenceAttributes may be null at this location LibSVMModel.java /RapidMiner_Unuk/src/com/rapidminer/operator/learner/functions/kernel line 231 Java Problem
Potential null pointer access: The variable creator may be null at this location ParameterTypeConfiguration.java /RapidMiner_Unuk/src/com/rapidminer/parameter line 111 Java Problem
Potential null pointer access: The variable current may be null at this location AbstractValueGrouping.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/configuration line 179 Java Problem
Potential null pointer access: The variable current may be null at this location AbstractValueGrouping.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/configuration line 198 Java Problem
Potential null pointer access: The variable current may be null at this location DistinctValueGrouping.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/configuration line 96 Java Problem
Potential null pointer access: The variable current may be null at this location DistinctValueGrouping.java /RapidMiner_Unuk/src/com/rapidminer/gui/new_plotter/configuration line 111 Java Problem
Potential null pointer access: The variable currentBestPerformance may be null at this location BackwardAttributeEliminationOperator.java

RM Staff
RM Staff

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

no but you do need to use Java 7 JDK for Eclipse.

Regards,
Marco
_________________________________________________________
Team Lead Software Engineering | RapidMiner GmbH
Contributor II ArmMiner
Contributor II

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

I get the ExampleSet object, but I can't print  the values. I used one of your example codes in the forum.
There is nullPointerException in my code. Could you please have a look?
Thanks!

import com.rapidminer.RapidMiner;
import com.rapidminer.RapidMiner.ExecutionMode;
import com.rapidminer.repository.IOObjectEntry;
import com.rapidminer.repository.RepositoryLocation;
import com.rapidminer.Process;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.Attributes;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.IOObject;


import java.io.File;
import java.util.Iterator;


public class Classification {
static Example exampleSet = null;

public static void main(String [] args) throws Exception{
ExampleSet resultSet1 = null;

// this initializes RapidMiner with your repositories available
// you have to call this for all your programs, otherwise your RapidMiner integration will not work correctly
RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
RapidMiner.init();
String xml = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" +
"<process version='5.3.007'>" +
"<context>" +
"<input/>" +
"<output/>" +
"<macros/>" +
"</context>" +
"<operator activated='true' class='process' compatibility='5.3.007' expanded='true' name='Process'>" +
"<process expanded='true'>" +
"<operator activated='true' class='read_excel' compatibility='5.3.007' expanded='true' height='60' name='Read Excel' width='90' x='45' y='165'>" +
"<parameter key='excel_file' value='C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\Training Data - Wieder.xls'/>" +
"<parameter key='imported_cell_range' value='A1:B276'/>" +
"<parameter key='first_row_as_names' value='false'/>" +
"<list key='annotations'/>" +
"<list key='data_set_meta_data_information'>" +
"<parameter key='0' value='Bewertung.true.text.attribute'/>" +
"<parameter key='1' value='Label.true.binominal.label'/>" +
"</list>" +
"</operator>" +
"<operator activated='true' class='text:process_document_from_data' compatibility='5.3.000' expanded='true' height='76' name='Process Documents from Data' width='90' x='45' y='30'>" +
"<parameter key='prune_method' value='absolute'/>" +
"<parameter key='prune_below_absolute' value='5'/>" +
"<parameter key='prune_above_absolute' value='9999'/>" +
"<parameter key='prune_above_rank' value='0.05'/>" +
"<list key='specify_weights'/>" +
"<process expanded='true'>" +
"<operator activated='true' class='text:tokenize' compatibility='5.3.000' expanded='true' height='60' name='Tokenize' width='90' x='44' y='30'/>" +
"<operator activated='true' class='text:transform_cases' compatibility='5.3.000' expanded='true' height='60' name='Transform Cases' width='90' x='179' y='30'/>" +
"<operator activated='false' class='text:filter_stopwords_german' compatibility='5.3.000' expanded='true' height='60' name='Filter Stopwords (German)' width='90' x='179' y='210'/>" +
"<operator activated='false' class='text:stem_german' compatibility='5.3.000' expanded='true' height='60' name='Stem (German)' width='90' x='313' y='255'/>" +
"<operator activated='true' class='text:generate_n_grams_terms' compatibility='5.3.000' expanded='true' height='60' name='Generate n-Grams (Terms)' width='90' x='447' y='30'>" +
"<parameter key='max_length' value='1'/>" +
"</operator>" +
"<connect from_port='document' to_op='Tokenize' to_port='document'/>" +
"<connect from_op='Tokenize' from_port='document' to_op='Transform Cases' to_port='document'/>" +
"<connect from_op='Transform Cases' from_port='document' to_op='Generate n-Grams (Terms)' to_port='document'/>" +
"<connect from_op='Generate n-Grams (Terms)' from_port='document' to_port='document 1'/>" +
"<portSpacing port='source_document' spacing='0'/>" +
"<portSpacing port='sink_document 1' spacing='0'/>" +
"<portSpacing port='sink_document 2' spacing='0'/>" +
"</process>" +
"</operator>" +
"<operator activated='false' class='store' compatibility='5.3.007' expanded='true' height='60' name='Store Wordlist' width='90' x='179' y='120'>" +
"<parameter key='repository_entry' value='Wordlist_Wieder'/>" +
"</operator>" +
"<operator activated='true' class='set_role' compatibility='5.3.007' expanded='true' height='76' name='Set Role' width='90' x='313' y='75'>" +
"<parameter key='attribute_name' value='Label'/>" +
"<parameter key='target_role' value='label'/>" +
"<list key='set_additional_roles'/>" +
"</operator>" +
"<operator activated='true' class='x_validation' compatibility='5.3.007' expanded='true' height='112' name='Validation' width='90' x='447' y='75'>" +
"<process expanded='true'>" +
"<operator activated='true' class='support_vector_machine_libsvm' compatibility='5.3.007' expanded='true' height='76' name='SVM' width='90' x='133' y='30'>" +
"<parameter key='gamma' value='0.9'/>" +
"<parameter key='C' value='8.0'/>" +
"<parameter key='epsilon' value='0.0010'/>" +
"<list key='class_weights'/>" +
"</operator>" +
"<connect from_port='training' to_op='SVM' to_port='training set'/>" +
"<connect from_op='SVM' from_port='model' to_port='model'/>" +
"<portSpacing port='source_training' spacing='0'/>" +
"<portSpacing port='sink_model' spacing='0'/>" +
          "<portSpacing port='sink_through 1' spacing='0'/>" +
          "</process>" +
          "<process expanded='true'>" +
          "<operator activated='true' class='apply_model' compatibility='5.3.007' expanded='true' height='76' name='Apply Model' width='90' x='24' y='30'>" +
          "<list key='application_parameters'/>" +
          "</operator>" +
          "<operator activated='true' class='performance' compatibility='5.3.007' expanded='true' height='76' name='Performance' width='90' x='179' y='30'/>" +
          "<connect from_port='model' to_op='Apply Model' to_port='model'/>" +
          "<connect from_port='test set' to_op='Apply Model' to_port='unlabelled data'/>" +
          "<connect from_op='Apply Model' from_port='labelled data' to_op='Performance' to_port='labelled data'/>" +
          "<connect from_op='Performance' from_port='performance' to_port='averagable 1'/>" +
          "<portSpacing port='source_model' spacing='0'/>" +
          "<portSpacing port='source_test set' spacing='0'/>" +
          "<portSpacing port='source_through 1' spacing='0'/>" +
          "<portSpacing port='sink_averagable 1' spacing='0'/>" +
          "<portSpacing port='sink_averagable 2' spacing='0'/>" +
          "</process>" +
          "</operator>" +
          "<operator activated='false' class='store' compatibility='5.3.007' expanded='true' height='60' name='Store Model' width='90' x='581' y='165'>" +
          "<parameter key='repository_entry' value='Stored_Model_Wieder'/>" +
          "</operator>" +
          "<operator activated='false' class='retrieve' compatibility='5.3.007' expanded='true' height='60' name='Retrieve Wordlist' width='90' x='45' y='480'>" +
          "<parameter key='repository_entry' value='Wordlist_Wieder'/>" +
          "</operator>" +
          "<operator activated='false' class='retrieve' compatibility='5.3.007' expanded='true' height='60' name='Retrieve' width='90' x='380' y='435'>" +
          "<parameter key='repository_entry' value='Stored_Model_Wieder'/>" +
          "</operator>" +
          "<operator activated='false' class='read_excel' compatibility='5.3.007' expanded='true' height='60' name='Read Excel (2)' width='90' x='45' y='570'>" +
          "<parameter key='excel_file' value='C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\HaendlerRatings_neu.xls'/>" +
          "<parameter key='imported_cell_range' value='A1:A2000'/>" +
          "<parameter key='first_row_as_names' value='false'/>" +
          "<list key='annotations'/>" +
          "<list key='data_set_meta_data_information'>" +
          "<parameter key='0' value='A.true.text.attribute'/>" +
          "</list>" +
          "</operator>" +
          "<operator activated='false' class='text:process_document_from_data' compatibility='5.3.000' expanded='true' height='76' name='Process Documents from Data (2)' width='90' x='313' y='525'>" +
          "<parameter key='prune_method' value='absolute'/>" +
          "<parameter key='prune_below_absolute' value='5'/>" +
          "<parameter key='prune_above_absolute' value='9999'/>" +
          "<parameter key='prune_above_rank' value='0.05'/>" +
          "<list key='specify_weights'/>" +
          "<process expanded='true'>" +
          "<operator activated='false' class='text:tokenize' compatibility='5.3.000' expanded='true' height='60' name='Tokenize (2)' width='90' x='45' y='30'/>" +
          "<operator activated='false' class='text:transform_cases' compatibility='5.3.000' expanded='true' height='60' name='Transform Cases (2)' width='90' x='180' y='30'/>" +
          "<operator activated='false' class='text:filter_stopwords_german' compatibility='5.3.000' expanded='true' height='60' name='Filter Stopwords (2)' width='90' x='246' y='210'/>" +
          "<operator activated='false' class='text:stem_german' compatibility='5.3.000' expanded='true' height='60' name='Stem (2)' width='90' x='179' y='255'/>" +
          "<operator activated='false' class='text:generate_n_grams_terms' compatibility='5.3.000' expanded='true' height='60' name='Generate n-Grams (2)' width='90' x='447' y='75'>" +
          "<parameter key='max_length' value='1'/>" +
          "</operator>" +
          "<connect from_port='document' to_op='Tokenize (2)' to_port='document'/>" +
          "<connect from_op='Tokenize (2)' from_port='document' to_op='Transform Cases (2)' to_port='document'/>" +
          "<connect from_op='Transform Cases (2)' from_port='document' to_op='Generate n-Grams (2)' to_port='document'/>" +
          "<connect from_op='Generate n-Grams (2)' from_port='document' to_port='document 1'/>" +
          "<portSpacing port='source_document' spacing='0'/>" +
          "<portSpacing port='sink_document 1' spacing='0'/>" +
          "<portSpacing port='sink_document 2' spacing='0'/>" +
          "</process>" +
          "</operator>" +
          "<operator activated='false' class='apply_model' compatibility='5.3.007' expanded='true' height='76' name='Apply Model (2)' width='90' x='581' y='525'>" +
          "<list key='application_parameters'/>" +
          "</operator>" +
          "<connect from_op='Read Excel' from_port='output' to_op='Process Documents from Data' to_port='example set'/>" +
          "<connect from_op='Process Documents from Data' from_port='example set' to_op='Set Role' to_port='example set input'/>" +
          "<connect from_op='Process Documents from Data' from_port='word list' to_op='Store Wordlist' to_port='input'/>" +
          "<connect from_op='Set Role' from_port='example set output' to_op='Validation' to_port='training'/>" +
          "<connect from_op='Validation' from_port='model' to_port='result 1'/>" +
          "<connect from_op='Validation' from_port='averagable 1' to_port='result 2'/>" +
          "<connect from_op='Retrieve Wordlist' from_port='output' to_op='Process Documents from Data (2)' to_port='word list'/>" +
          "<connect from_op='Retrieve' from_port='output' to_op='Apply Model (2)' to_port='model'/>" +
          "<connect from_op='Read Excel (2)' from_port='output' to_op='Process Documents from Data (2)' to_port='example set'/>" +
          "<connect from_op='Process Documents from Data (2)' from_port='example set' to_op='Apply Model (2)' to_port='unlabelled data'/>" +
          "<portSpacing port='source_input 1' spacing='0'/>" +
          "<portSpacing port='sink_result 1' spacing='234'/>" +
          "<portSpacing port='sink_result 2' spacing='0'/>" +
          "<portSpacing port='sink_result 3' spacing='0'/>" +
          "</process>" +
          "</operator>" +
          "</process>";
Process pr = new Process(xml);
IOContainer ioInput = null;
IOContainer ioResult = pr.run(ioInput);
if (ioResult.getElementAt(0) instanceof ExampleSet) {
resultSet1 = (ExampleSet)ioResult.getElementAt(0);
System.out.println(resultSet1);
}
// note: resultSet must be instanceof ExampleSet
for (Example example : resultSet1) {
Iterator<Attribute> allAtts = exampleSet.getAttributes().allAttributes();
while(allAtts.hasNext()) {
Attribute a = allAtts.next();
                if (a.isNumerical()) {
                        double value = example.getValue(a);
                        System.out.println(value);
                } else {
                        String value = example.getValueAsString(a);
                        System.out.println(value);
                }
        }
}
          }
}


And this is the error:
INFO: Process finished successfully after 0 s
Exception in thread "main" java.lang.NullPointerException
at Classification.main(Classification.java:177)
RM Staff
RM Staff

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

first of all, let me suggest to never include the XML of a process into your code, it makes it a) hard to read and b) hard to find the problem because I can't just copy&paste the XML into RapidMiner. I suggest to either use new Process(new File(/*pathToFile*/)) or Tools.readTextFile(new File(/*pathToFile*/)) in case you do not want to use the Repository.
Having said that, the only possible way for your NPE is when your RapidMiner process simply returns nothing or it is not an ExampleSet because the for-loop is not included in the previous IF block.
Make sure your RM process returns the desired result when executed in RapidMiner.

Regards,
Marco
_________________________________________________________
Team Lead Software Engineering | RapidMiner GmbH
Contributor II ArmMiner
Contributor II

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

Thanks, now it works.
My idea is to give the input file for test from my application and as an output have only 'Prediction' column saved in a *.xls file. Could you please give some hints which methods shal I use for this purpose?
Thanks!

Best regards
Armen
RM Staff
RM Staff

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

create a RapidMiner process that does exactly that (have a look at Select Attributes and Write Excel operators), then use said process, edit the parameter for the input file (and maybe the output file) and execute it.

Regards,
Marco
_________________________________________________________
Team Lead Software Engineering | RapidMiner GmbH
Contributor II ArmMiner
Contributor II

Re: How to use a trained classification model of RapidMIner in my Java application?

What do you mean by saying "edit the parameter for the input file"? I want to change the file from the code, so that every time I will not do that in RapidMiner. Could you provide a little example?
Thanks!

Best regards
Armen
RM Staff
RM Staff

Re: How to use a trained classification model of RapidMIner in my Java application?

Hi,

I posted that in my first answer Smiley Happy
http://rapid-i.com/rapidforum/index.php/topic,6476.msg22727.html#msg22727

Regards,
Marco
_________________________________________________________
Team Lead Software Engineering | RapidMiner GmbH
Polls
How can RapidMiner increase participation in our new competitions?
Twitter Feed