https://github.com/retrooper/bigdata
https://github.com/retrooper/bigdata
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/retrooper/bigdata
- Owner: retrooper
- Created: 2024-08-06T19:13:17.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-10T19:04:50.000Z (almost 2 years ago)
- Last Synced: 2025-09-06T22:37:37.083Z (11 months ago)
- Language: Java
- Size: 4.72 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# *bigdata*
Easy to use Machine Learning library written in Java, powered by OpenCV.
## Linear Regression Algorithm

### Implementing Linear-Regression
```java
//Data samples
float[] input = new float[]{
-1f, 0f, 1f, 2f
};
//Supervised output
float[] output = new float[]{
-2f, 0f, 2f, 4f
};
//Specify the dataset
LabeledDataset2D function = new LabeledDataset2D(input, output);
//Specify the learning algorithm (linear regression)
Supplier> dataSupplier = () -> LinearRegressionAlgorithm.build(function);
TrainingModel trainingModel = new TrainingModel<>();
//Train the model
ProductionModel trainedModel = trainingModel.train(dataSupplier);
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("What X value should we predict based on the data?");
String line = scanner.nextLine();
try {
float x = (float)Double.parseDouble(line);
//Predict with the model.
System.out.println("X: " + x + ", y: " + trainedModel.predict(x));
}
catch (Exception exception) {
break;
}
}
```
## K-Means Clustering Algorithm

### Implementing K-Means Clustering Algorithm
```java
//Unsupervised data, we expect to cluster
float[] input = new float[]{
1.1f, 1.1f, 1.1f, 1.4f, 3f, 3.2f, 3.3f, 3.4f, 5f, 5f, 5f
};
//Dataset
UnlabeledDataset1D function = new UnlabeledDataset1D(input);
//Learning algorithm with 3 clusters (groups), with 5 iterations
Supplier> dataSupplier = () -> KMeansClusteringAlgorithm.build(3, function, 5);
TrainingModel trainingModel = new TrainingModel<>();
ProductionModel trainedModel = trainingModel.train(dataSupplier);
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("What cluster should we put X in, good grades (1), mid grades (2), bad grades (3)");
String line = scanner.nextLine();
try {
float x = (float) Double.parseDouble(line);
//Predict with the model
System.out.println("X: " + x + " in cluster: " + trainedModel.predict(new NDimensionalPoint(x)));
} catch (Exception exception) {
break;
}
}
}
```