Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilayerperceptron example added with seaborndataset #51

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example/gradle/wrapper/gradle-wrapper.properties
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have already gradle wrapper. Delete this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.example.nn;


import de.edux.api.Classifier;
import de.edux.functions.activation.ActivationFunction;
import de.edux.functions.initialization.Initialization;
import de.edux.functions.loss.LossFunction;
import de.edux.ml.knn.KnnClassifier;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this import

import de.edux.ml.nn.config.NetworkConfiguration;
import de.edux.ml.nn.network.MultilayerPerceptron;
import de.edux.ml.nn.network.api.Dataset;
import de.example.data.seaborn.Penguin;
import de.example.data.seaborn.SeabornDataProcessor;
import de.example.data.seaborn.SeabornProvider;

import java.io.File;
import java.util.List;

/**
* Knn - K nearest neighbors
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this copy pasted part. Wrong JavaDoc here.

* Dataset: Seaborn Penguins
*/
public class MultilayerPerceptronExample2 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to MultilayerPerceptronSeabornExample

Also Rename the old MultilayerPerceptronExample class to MultilayerPerceptronIrisExample

private static final boolean SHUFFLE = true;
private static final boolean NORMALIZE = true;
private static final boolean FILTER_INCOMPLETE_RECORDS = true;
private static final double TRAIN_TEST_SPLIT_RATIO = 0.75;
private static final File CSV_FILE = new File("example" + File.separator + "datasets" + File.separator + "seaborn-penguins" + File.separator + "penguins.csv");

public static void main(String[] args) {
var seabornDataProcessor = new SeabornDataProcessor();
List<Penguin> data = seabornDataProcessor.loadDataSetFromCSV(CSV_FILE, ',', SHUFFLE, NORMALIZE, FILTER_INCOMPLETE_RECORDS);

Dataset<Penguin> dataset = seabornDataProcessor.split(data, TRAIN_TEST_SPLIT_RATIO);
var seabornProvider = new SeabornProvider(data, dataset.trainData(), dataset.testData());
seabornProvider.printStatistics();
double[][] features = seabornProvider.getTrainFeatures();
double[][] labels = seabornProvider.getTrainLabels();

double[][] testFeatures = seabornProvider.getTestFeatures();
double[][] testLabels = seabornProvider.getTestLabels();

NetworkConfiguration networkConfiguration = new NetworkConfiguration(seabornProvider.getTrainFeatures()[0].length, List.of(32, 6), 3, 0.01, 1000, ActivationFunction.LEAKY_RELU, ActivationFunction.SOFTMAX, LossFunction.CATEGORICAL_CROSS_ENTROPY, Initialization.XAVIER, Initialization.XAVIER);

MultilayerPerceptron multilayerPerceptron = new MultilayerPerceptron(networkConfiguration, testFeatures, testLabels);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have unified Interface for all classifiers. Replace datatype here with

Classifier multilayerPerceptron = ...

multilayerPerceptron.train(seabornProvider.getTrainFeatures(), labels);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You defined already double[][] features = seabornProvider.getTrainFeatures();

Replace your seabornProvider.getTrainFeatures() call here, with variable features

multilayerPerceptron.evaluate(testFeatures, testLabels);
}

}
Loading