How to do it...

  1. Create an array to assign weights to minor labels:
INDArray weightsArray = Nd4j.create(new double[]{0.35, 0.65});
  1. Modify OutPutLayer to evenly balance the labels in the dataset:
new OutputLayer.Builder(new LossMCXENT(weightsArray)).nIn(incomingConnectionCount).nOut(labelCount).activation(Activation.SOFTMAX))
.build();
  1. Initialize the neural network and add the training listeners:
MultiLayerConfiguration configuration = builder.build();
MultiLayerNetwork multiLayerNetwork = new MultiLayerNetwork(configuration);
multiLayerNetwork.init();
multiLayerNetwork.setListeners(new ScoreIterationListener(iterationCount));
  1. Add the DL4J UI Maven dependency to analyze the training process:
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-ui_2.10</artifactId>
<version>1.0.0-beta3</version>
</dependency>
  1. Start the UI server and add temporary storage to store the model information:
UIServer uiServer = UIServer.getInstance();
StatsStorage statsStorage = new InMemoryStatsStorage();

Replace InMemoryStatsStorage with FileStatsStorage (in case of memory restrictions):

multiLayerNetwork.setListeners(new ScoreIterationListener(100),
new StatsListener(statsStorage));
  1. Assign the temporary storage space to the UI server:
uiServer.attach(statsStorage);
  1. Train the neural network by calling fit():
multiLayerNetwork.fit(dataSetIteratorSplitter.getTrainIterator(),100);
  1. Evaluate the model by calling evaluate():
Evaluation evaluation = multiLayerNetwork.evaluate(dataSetIteratorSplitter.getTestIterator(),Arrays.asList("0","1"));
System.out.println(evaluation.stats()); //printing the evaluation metrics
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset