-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSimpleLinearRegressionExample.java
More file actions
44 lines (36 loc) · 1.7 KB
/
SimpleLinearRegressionExample.java
File metadata and controls
44 lines (36 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package jsr381.example;
import jsr381.example.util.DataSetExamples;
import javax.visrec.ri.ml.regression.SimpleLinearRegressionNetwork;
import javax.visrec.ml.regression.SimpleLinearRegression;
import java.io.IOException;
import javax.visrec.ml.data.DataSet;
/**
* This example uses a Swedish Auto Insurance Dataset to predict the total
* payment for all auto insurance claims (in thousands of Swedish Kronor),
* given the total number of claims.
*
* This example shows how to instantiate, train, evaluate and use Linear Regression
* using Machine Learning Layer from VisRec API.
*
* @author Zoran Sevarac
*/
public class SimpleLinearRegressionExample {
public static void main(String[] args) throws IOException {
// Create a DataSet object from the CSV file
DataSet dataSet = DataSetExamples.getSwedishAutoInsuranceDataSet();
// Build the model
SimpleLinearRegression linReg = SimpleLinearRegressionNetwork.builder()
.trainingSet(dataSet)
.learningRate(0.1f)
.maxError(0.01f)
.build();
// Display information about the trained model
float slope = linReg.getSlope();
float intercept = linReg.getIntercept();
System.out.println("Trained Model y = " + slope + " * x + " + intercept);
// Predict the outcome based on some input.
float someInput = 0.10483871f;
Float prediction = linReg.predict(someInput);
System.out.println("predicted output for " + (someInput*124) + " is:" + (prediction*422.2));
}
}