-
Notifications
You must be signed in to change notification settings - Fork 0
aurora: Linear Regression
Clouke edited this page May 4, 2023
·
1 revision
LinearRegression lr = new LinearRegressionBuilder()
.learningRate(0.01) // define the learning rate
.epochs(100_000) // define the epochs
.printing(Bar.CLASSIC) // define the progress bar (optional) - Bar.CLASSIC by default
.build();
Create a Data Set:
double[] x = new double[] {1, 2, 3, 4, 5};
double[] y = new double[] {2, 4, 6, 8, 10};
Fit the model with the data set:
lr.fit(x, y);
Printing: Printing comes with attributes, providing information about the training process:
-
Loss
: Represents the decreasing error which means the model is improving -
Stage
: Represents the current stage in the training process, which goes to 100 when it is completed -
Accuracy
: Represents the accuracy score of the model, whereas you may useHyperparameterTuning
for the best score -
Epoch
: Represents the current iteration
[###############################] Loss: 2.8398992587956425E-29 | Stage: 100 | Accuracy: 0.9 | Epoch: 99500 (—)
double[] output = lr.predict(new double[]{6, 7, 8, 9, 10});
Save your Linear Regression Model:
Model model = lr.toModel();
model.save("my_directory");
Load from file:
LinearRegressionModel model = null;
try (ModelLoader loader = new ModelLoader(new File("my_directory"))) {
model = loader.load(LinearRegressionModel.class);
}
Load from URL:
LinearRegressionModel model = null;
try (ModelLoader loader = new ModelLoader(new URL("my_model_url"))) {
model = loader.load(LinearRegressionModel.class);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}