'Linear Regression to predict a simple formula result using Weka
I have a simple train data as follow. The result is calculated by formula (price * 100).
Train Data
Price, Result
1, 100
15, 1500
2.3, 230
5.23, 523
3.245, 324.5
100, 1000
Test Data
Price, Result
4.567, 456.7 (this result 456.7 to be predicted by formula price * 100)
Is there a way to do it by Weka?
Solution 1:[1]
I have fixed your datasets, turning them into valid CSV format:
Train
Price,Result
1,100
15,1500
2.3,230
5.23,523
3.245,324.5
100,10000
NB: The last line also required 10,000, not 1000 as Result value to comply with your rule of Result = Price * 100.
Test
Price,Result
4.567,456.7
Build model
You can build a model, either using weka.classifiers.functions.LinearRegression or weka.classifiers.functions.SimpleLinearRegression from the terminal like this (and output the generated rule):
java -cp weka.jar weka.classifiers.functions.SimpleLinearRegression -t train.csv -T test.csv
NB: You will need to adjust paths to the weka.jar and your train/test CSV files.
Predictions
If you want to output predictions for the test set, then you can use something like this:
java -cp weka.jar weka.classifiers.functions.SimpleLinearRegression -t train.csv -T test.csv -classifications weka.classifiers.evaluation.output.prediction.PlainText
NB: You will need to adjust paths to the weka.jar and your train/test CSV files.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fracpete |
