Skip to content
Snippets Groups Projects
Commit 02b0aba6 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Working linear regression

parent 7fd96b46
Branches
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import javafx.scene.chart.XYChart;
import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import java.util.*;
......@@ -110,7 +111,6 @@ public class LineChartFunctionality {
multiMap.computeIfAbsent(index, k -> new ArrayList<Double>());
multiMap.get(index).add(kwhValue);
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(index), kwhValue));
index += 1;
......@@ -118,9 +118,43 @@ public class LineChartFunctionality {
updateLineChart(newSeries);
}
// Stores the data from the confidence interval in a new map
Map<Integer, ArrayList<Double>> confidenceIntervalData = statistics(multiMap);
// Checks the max size for the arraylists needed for the data array later
int jMaxSize = 0;
for (int i = 0; i < confidenceIntervalData.size(); i++) {
if(confidenceIntervalData.get(i).size() > jMaxSize){
jMaxSize = confidenceIntervalData.get(i).size();
}
}
// Defines an array to be used for the regression
double[][] data = new double[confidenceIntervalData.size()][jMaxSize];
System.out.println(confidenceIntervalData);
for (int i = 0; i < confidenceIntervalData.size(); i++) {
ArrayList<Double> list = confidenceIntervalData.get(i);
for (int j = 0; j < list.size(); j++) {
data[i][j] += list.get(j);
}
}
System.out.println(data.length);
System.out.println(data[12][1]);
SimpleRegression simpleRegression = new SimpleRegression();
simpleRegression.addData(data);
// and then you can predict the time at a given temperature value
System.out.println("Predicted Time: " + simpleRegression.predict(35));
// You can also get the slope and intercept from your data
System.out.println("slope = " + simpleRegression.getSlope());
System.out.println("intercept = " + simpleRegression.getIntercept());
//simpleRegression.add
return getLineChart();
}
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment