-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have unified Interface for all classifiers. Replace datatype here with
|
||
multilayerPerceptron.train(seabornProvider.getTrainFeatures(), labels); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You defined already Replace your seabornProvider.getTrainFeatures() call here, with variable features |
||
multilayerPerceptron.evaluate(testFeatures, testLabels); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.