RapidMiner

Integrating RapidMiner with Java Application

Contributor II nelze
Contributor II

Re: Integrating RapidMiner with Java Application

Thank you very much! I was able to get the prediction results. I have another question though...

How do I prevent the first row of my test data from becoming a column name? I just noticed that my test data has 50 rows, but the prediction only gives 49 values.
RM Staff
RM Staff

Re: Integrating RapidMiner with Java Application

Hi,

you can configure that in the Read Excel or Read CSV operator. See the "first row as names" parameter on them.

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

Re: Integrating RapidMiner with Java Application

Good day! I was going to add the dynamic input of file, but now I get this error

com.rapidminer.operator.UserError: No input file was defined.

Any hints? I continued off from my last post
f = the file obtained dynamically

Process process = new Process(new File("C:\\Users\\nelze\\.RapidMiner5\\repositories\\WalkingRepo\\NaiveClassify.rmp"));
     Operator op = process.getOperator("Read CSV");
     op.setParameter(CSVExampleSource.PARAMETER_FILENAME, f);
     IOContainer ioResult = process.run();
     ExampleSet resultSet1 = (ExampleSet)ioResult.getElementAt(0);
     Iterator<Attribute> allAttributes = resultSet1.getAttributes().allAttributes();
     while (allAttributes.hasNext()) {
      Attribute att = allAttributes.next();
      for (Example example : resultSet1) {
      if (att.isNominal()) {
      System.out.println(example.getNominalValue(att));
      }
      }
     }

My rapidminer process is still the same.
It also keeps telling me that CSVExampleSource is deprecated, but when I run this code and change CSV to Excel (I change all my csv files to excel too), it works properly. However, I can't use Excel because I need to import more libraries in Java. Is there an updated command for CSV?
RM Staff
RM Staff

Re: Integrating RapidMiner with Java Application

Hi,

sorry, my bad. com.rapidminer.operator.nio.CSVExampleSource is the correct one, com.rapidminer.operator.io.CSVExampleSource is outdated and no longer used. You can see that as well when using the debugger and adding a breakpoint after calling process.getOperator("Read CSV"); and you will notice that op is an instance of the new version. This also changes the file parameter to com.rapidminer.operator.nio.CSVExampleSource.PARAMETER_CSV_FILE.

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

Re: Integrating RapidMiner with Java Application

Thank you very much!

I was wondering also if there's a way to have string inputs in rapidminer? Because I was also planning to have the classification done in real time so it would take up a lot of space if  I had to create a text file each and every time.
RM Staff
RM Staff

Re: Integrating RapidMiner with Java Application

Hi,

you can exchange the "Read XYZ" operator with a direct connection from the process input port on the far left to your other operators. That way the exampleSet is not created by the "Read XYZ" operator but rather has to be supplied when running the process as a parameter for the run() method. You can create an exampleSet manually and set the values for all cells yourself.
See here for an example: http://rapid-i.com/rapidforum/index.php/topic,5531.msg19614.html#msg19614

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

Re: Integrating RapidMiner with Java Application

Hi! Unfortunately, when I try to use com.rapidminer.operator.nio.CSVExampleSource  and do the PARAMETER_CSV_FILE, it still gives the com.rapidminer.operator.UserError: No input file was defined.

I use it as
Operator op = process.getOperator("Read CSV");
op.setParameter(CSVExampleSource.PARAMETER_CSV_FILE, f);

where f is the filename
RM Staff
RM Staff

Re: Integrating RapidMiner with Java Application

Hi,

can you please post the full relevant code and the full error log?

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

Re: Integrating RapidMiner with Java Application

    try {
      RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
      RapidMiner.init();

      Process process = new Process(new File("C:\\Users\\nelze\\.RapidMiner5\\repositories\\WalkingRepo\\NaiveClassify.rmp"));
     
      Operator op = process.getOperator("Read CSV");
      op.setParameter(CSVExampleSource.PARAMETER_CSV_FILE, "C:\\Users\\nelze\\Desktop\\unlabeled.csv");

     
      IOContainer ioResult = process.run();
      ExampleSet resultSet1 = (ExampleSet)ioResult.getElementAt(0);
      Iterator<Attribute> allAttributes = resultSet1.getAttributes().allAttributes();
      while (allAttributes.hasNext()) {
      Attribute att = allAttributes.next();
      for (Example example : resultSet1) {
      if (att.isNominal()) {
      System.out.println(example.getNominalValue(att));
      }
      }
      }

    } catch (IOException | XMLException | OperatorException ex) {
      ex.printStackTrace();
    }
 

The stack trace is as follows

INFO: Process C:\Users\nelze\.RapidMiner5\repositories\WalkingRepo\NaiveClassify.rmp starts
com.rapidminer.operator.UserError: No input file was defined.
at com.rapidminer.operator.nio.model.CSVResultSet.openStream(CSVResultSet.java:137)
at com.rapidminer.operator.nio.model.CSVResultSet.open(CSVResultSet.java:79)
at com.rapidminer.operator.nio.model.CSVResultSet.<init>(CSVResultSet.java:73)
at com.rapidminer.operator.nio.model.CSVResultSetConfiguration.makeDataResultSet(CSVResultSetConfiguration.java:114)
at com.rapidminer.operator.nio.model.AbstractDataResultSetReader.createExampleSet(AbstractDataResultSetReader.java:127)
at com.rapidminer.operator.io.AbstractExampleSource.read(AbstractExampleSource.java:52)
at com.rapidminer.operator.io.AbstractExampleSource.read(AbstractExampleSource.java:36)
at com.rapidminer.operator.io.AbstractReader.doWork(AbstractReader.java:126)
at com.rapidminer.operator.Operator.execute(Operator.java:866)
at com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:51)
at com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:711)
at com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:375)
at com.rapidminer.operator.Operator.execute(Operator.java:866)
at com.rapidminer.Process.run(Process.java:949)
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 NaiveClassifier.main(NaiveClassifier.java:34)
Highlighted
Contributor II nelze
Contributor II

Re: Integrating RapidMiner with Java Application

Nevermind, there was just a problem in the port. Although I get some weird happenings...

If I input the data dynamically, the result is different as when I manually put the file on my PC (I usually compare things to validate them) even though they have the same values. For example, the dynamically entered file returns predictions of 1,1,3,4 but when I run the file from my PC, it gives 1,2,3,4 even if it's using the same model and have exactly the same values.