Numeric Prediction (One Day Ahead) using Weka API

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Numeric Prediction (One Day Ahead) using Weka API

Gaetano
Hi
I would like to predict the value of the class attribute based on a specific date using java weka api.

My dataset has the following structure:
@attribute idsito numeric
@attribute data date yyyy-MM-dd
@attribute id.x numeric
@attribute temperatura_ambiente.x numeric
@attribute irradiamento numeric
@attribute kwh numeric

I created testSet that contains current day data (I imposted all values of target variable kwh at '?') and trainingSet that contains past days data.
How can I invoke weka algorithms using trainingSet and testSet with java Weka API? Also, which algoritms are reccommended for numeric prediction?

Thanks
Cheers
Gaetano
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Numeric Prediction (One Day Ahead) using Weka API

Eibe Frank-2
Administrator
Use the buildClassifier(Instances) method to feed training data to the learning algorithm and make it learn a classifier. Use classifyInstance(Instance) to obtain a numeric prediction for an instance once a model has been built.

The M5P model tree learner in the trees package is a good candidate to start with.

Cheers,
Eibe

> On 12/05/2017, at 6:27 AM, Gaetano <[hidden email]> wrote:
>
> Hi
> I would like to predict the value of the class attribute based on a specific
> date using java weka api.
>
> My dataset has the following structure:
> @attribute idsito numeric
> @attribute data date yyyy-MM-dd
> @attribute id.x numeric
> @attribute temperatura_ambiente.x numeric
> @attribute irradiamento numeric
> @attribute kwh numeric
>
> I created testSet that contains current day data (I imposted all values of
> target variable kwh at '?') and trainingSet that contains past days data.
> How can I invoke weka algorithms using trainingSet and testSet with java
> Weka API? Also, which algoritms are reccommended for numeric prediction?
>
> Thanks
> Cheers
> Gaetano
>
>
>
> --
> View this message in context: http://weka.8497.n7.nabble.com/Numeric-Prediction-One-Day-Ahead-using-Weka-API-tp40590.html
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Numeric Prediction (One Day Ahead) using Weka API

Gaetano
Ok I wrote this code and prediction seems to work fine but when I compute rootMeanSquareError, the result is NaN.
My intention is to compute RMSE for every prediction.

This is my code:
//build model
   M5P  predictor = new M5P ();
   predictor.buildClassifier(trainingSet);
   //loop through the new dataset and make predictions
   for (int i = 0; i < testSet.numInstances(); i++)
   {
        double pred = predictor.classifyInstance(testSet.instance(i));
        System.out.print("ID PLANT: " + testSet.instance(i).value(2));
        System.out.println(", predicted: " + pred);
        // evaluate classifier and print some statistics
        Evaluation eval = new Evaluation(trainingSet);
        eval.evaluateModel(predictor, testSet);
        System.out.println(eval.rootMeanSquaredError());
   }

The result is:
ID PLANT: 186826.0, predicted: 143517.43610664003
NaN
ID PLANT: 15588.0, predicted: -293.89710174995867
NaN
ID PLANT: 157969.0, predicted: 17390.278698668815
NaN
ID PLANT: 170591.0, predicted: 17392.53664785647
NaN
.....

I would know why RMSE assumes for every instance "NaN" value and if it is normal if some "predicted" values assumes negative values.

Cheers
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Numeric Prediction (One Day Ahead) using Weka API

Eibe Frank-2
Administrator
The RMSE cannot be computed if the target values in the test data are missing. In that case, there is nothing the predictions can be compared to!

Yes, negative values are possible. M5P builds a decision tree with linear regression models at the leaf nodes. Those linear regression models can give negative predictions, even if none of the target values in the training data are negative.

Cheers,
Eibe

> On 13 May 2017, at 19:18, Gaetano <[hidden email]> wrote:
>
> Ok I wrote this code and prediction seems to work fine but when I compute
> rootMeanSquareError, the result is NaN.
> My intention is to compute RMSE for every prediction.
>
> This is my code:
> //build model
>   M5P  predictor = new M5P ();
>   predictor.buildClassifier(trainingSet);
>   //loop through the new dataset and make predictions
>   for (int i = 0; i < testSet.numInstances(); i++)
>   {
> double pred = predictor.classifyInstance(testSet.instance(i));
> System.out.print("ID PLANT: " + testSet.instance(i).value(2));
> System.out.println(", predicted: " + pred);
> // evaluate classifier and print some statistics
> Evaluation eval = new Evaluation(trainingSet);
> eval.evaluateModel(predictor, testSet);
>        System.out.println(eval.rootMeanSquaredError());
>   }
>
> The result is:
> ID PLANT: 186826.0, predicted: 143517.43610664003
> NaN
> ID PLANT: 15588.0, predicted: -293.89710174995867
> NaN
> ID PLANT: 157969.0, predicted: 17390.278698668815
> NaN
> ID PLANT: 170591.0, predicted: 17392.53664785647
> NaN
> .....
>
> I would know why RMSE assumes for every instance "NaN" value and if it is
> normal if some "predicted" values assumes negative values.
>
> Cheers
>
>
>
>
> --
> View this message in context: http://weka.8497.n7.nabble.com/Numeric-Prediction-One-Day-Ahead-using-Weka-API-tp40590p40598.html
> Sent from the WEKA mailing list archive at Nabble.com.
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
List info and subscription status: https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Numeric Prediction (One Day Ahead) using Weka API

Gaetano
Hi Eibe
Can you suggest some other algorithm beyond M5P to make numerical prediction? So that I can compare the results of M5P with the results of other algorithms.

Thanks
Loading...