🎉 🎉 RAPIDMINER 9.10 IS OUT!!! 🎉🎉

Download the latest version helping analytics teams accelerate time-to-value for streaming and IIOT use cases.

CLICK HERE TO DOWNLOAD

"training model in java"

laurablaurab Member Posts: 23  Maven
edited May 2019 in Help
Hi,

I want to train a W-MultilayerPerceptron in a java application but I am having trouble with creating the W-MulitlayerPerceptron. 

First of I tried to the normal way of creating an operator as in the following code snippet:

1  " Operator model = OperatorService.createOperator("W-MultilayerPerceptron");
model.setParameter("keep_example_set", "true");
model.setParameter("L", "0.3"); //learning rate "

When run using this code I get an error "No Operator Description for W-MultilayerPerceptron".  I have looked into the OperatorDescription but it did not seem like it would help? I have definaltey included weka.jar on the build Path.

Then I used the following snippet (which I found on this help forum):
2. "// do not have an own class ( derived from the Weka library ).
Learner learner = (Learner)OperatorService.createOperator("W-MultilayerPerceptron"); "

snippet 2  in the example I got it from was for the "J48" learner in the weka librabry. It was mentioned how important the "W" on the front of weka  operators is but then the operator in the example was explicity reffered to as "J48" not "Wj48".

But when using the learning,  I could not see anyway of adjusting the parameters such as learning rate etc. Also, currently the java app is setting up a process and from the looks of things Learner does not fit that comfortably.

Finaly,  I found another example on this forum where an XML file is created via a String in the Java App

Snippet 3
  "String myOperatorsString = "<operator name=\"ExampleSource\" class\"ExampleSource\">" +
"<parameter key=\"attributes\" value=\"" + attributesFile + "\">" +
"<parameter key=\"sample_ratio\" value=\"0.5\">" +
"<operator name=\"XValidation\" class=\"XValidation\" expanded=\"yes\">" +
" <operators name=\"OperatorChain\">" +
"<operator name=\"W-MultilayerPerceptron\" class=\"W-MultilayerPerceptron\" /></operators>" +
"<parameter key=\"n\" value=\"1\">" +
"<operator name=\"ModelWriter\" class=\"ModelWriter\">" +
"<parameter key=\"model_file\" value=\"C:/Documents and Settings/laurab/My Documents/java NN/mlp model/EF_TX_MKRESP_Geo_-All_TC_12M.mod\">" +
    "</operator>" +
  "</operators>" +
"<operators name=\"OperatorChain\">" +
"<operator name=\"ModelApplier\" class=\"ModelApplier\" /></operators>" +
"<operator name=\"RegressionPerformance\" class=\"RegressionPerformance\">" +
"<parameter key=\"absolute_error\" value=\"true\"/></operator>" +
                "<operator name=\"PerformanceWriter\" class=\"PerformanceWriter\">" +
                "<parameter key=\"performance_file\" value=\"" + performanceFile + "\"/> </operator>" + ...
     
But I only wanted to go down this path if there really is no other way of using the W-MLP

I really hope some one can help!

Cheers, Laura
Tagged:

Answers

  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi Laura,
    did you initialized RapidMiner correctly? If you call RapidMiner.init  there is a parameter if weka operators should be loaded...
    The two code snippets seems to me to be identically. Just remove the cast and you will have an Operator to set parameters.

    Greetings,
      Sebastian
  • laurablaurab Member Posts: 23  Maven
    Hi Sebastian,

    I think I am initilising rapidMiner correctly:

    "RapidMiner.init(true, false, false, true);"

    And I have included weka.jar but when the application is run it says :

        Load Weka operators: weka not found        ??

    I tried removing the cast as so:
         
    Learner learner = OperatorService.createOperator("W-MultilayerPerceptron");

    I may not have done that correctly, But the compiler does not like that.

         
    In theory then, if Load weka operators completes fine then should the following work?

          Operator model = OperatorService.createOperator("W-MultilayerPerceptron");

    Although no matter where i put the weka.jar file it does not get found

    Thanks Laura


  • laurablaurab Member Posts: 23  Maven
    Hi again Sebastian,

    On a previous thread you said that I could use

    <operator name="AttributeConstruction" class="AttributeConstruction">
            <list key="function_descriptions">
              <parameter key="prediction_nonNegative" value="if (prediction &lt; 0, 0, prediction)"/>
            </list>
        </operator>

    For postProcessing, for setting negative values to 0. However when I try to use this in my java app I get


    G Nov 26, 2008 2:46:27 PM: Loading JDBC driver information from 'resources:jdbc_properties.xml'.
    com.rapidminer.operator.OperatorCreationException: No operator description object given for 'AttributeConstruction'
    at com.rapidminer.tools.OperatorService.createOperator(OperatorService.java:531)
    at NeuralNetPredictor.createProcess(NeuralNetPredictor.java:137)
    at NeuralNetPredictor.controlMethod(NeuralNetPredictor.java:51)
    at demandForecasting.main(demandForecasting.java:14)
    P Nov 26, 2008 2:46:27 PM: Initialising process setup

    I am creating the operator as follows:

    Operator AttributeConstruction = OperatorService.createOperator("AttributeConstruction");
    AttributeConstruction.setParameter("prediction_nonNegative", "if (prediction &lt; 0, 0, prediction)");

    Then adding it to my process.  Do I need to be including any extra .jar files, or anything or any particlur "Imports"? Or am I using the method for creating this operator. I am unable to find any examples for  this

    Sorry to bombard you with questions!.

    Cheers Laura
  • landland RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 2,531   Unicorn
    Hi Laura,
    one comment not dependet on the problem:
    Try using an IDE like eclipse. It will make your life much much much easier. Things like
    Operator AttributeConstruction = OperatorService.createOperator("AttributeConstruction");
                AttributeConstruction.setParameter("prediction_nonNegative", "if (prediction &lt; 0, 0, prediction)");
    are not Java conform and the IDE will instantly give a hint that AttributeConstruction is a variable and is strongly recommended to be written lowercase.

    The other thing is: AttributeConstruction is a new Operator of the release 4.3. If you still use 4.2 this operator is unkown...

    Greetings,
      Sebastian
  • laurablaurab Member Posts: 23  Maven
    Hi Sebastian,

    Thanks for your reply, I was still using 4.2 so have changed to 4.3.

    I am already using eclipse.  But just changing to 4.3 seems to hiave fixed most of my problems.  It is no longer complaining about OperatorDescription for the W-MLP. 

    Thanks a lot for all the  help

    Laura
Sign In or Register to comment.