Skip to content
Advertisement

Training on multiple data sets with scikit.mlpregressor

I’m currently training my first neural network on a larger dataset. I have splitted my training data to several .npy binary files, that each contain batches of 20k training samples. I’m loading the data from the npy files, apply some simple pre-processing operations, and then start to train my network by applying the partial_fit method several times in a loop:

JavaScript

I read already, that the regular .fit() method is not capable of training with multiple batches, but partial_fit in contrary should be able to do it.. My first training run goes always well. The loss is decreasing, and I get nice fitting results, so I save my model using the joblib.dump method. For the next call I’m using exactly the same script again, that loads my data from the .npy files (doesn’t matter if I feed the same batch, or another one), pre-process it, this time load my pre-trained model with joblib.load, and start doing the partial_fit loop again. What I always get in the second run is a constant loss over all iterations, the error is not decreasing anymore, no matter what dataset I use:

JavaScript

What am I doing wrong here? Thanks already!

Advertisement

Answer

There are several possibilities.

  1. The model may have converged
  2. There may not be enough passes over the batches (in the example below the model doesn’t converge until ~500 iterations)
  3. (Need more info) the joblib.dump and joblib.load may be saving or loading in an unexpected way

Instead of calling a script multiple times and dumping the results between iterations, it might be easier to debug if initializing/preprocessing/training/visualizing all happens in one script. Here is a minimal example:

JavaScript

Output:

Graph showing the training loss in the left plot and test score on the right plot. Loss goes to zero, score goes to 1.0.

Advertisement