Online Learning for HyperStream.
- Requirements
- Unittest
- Run a simple classification test
- Example with Keras
- Example of Anomaly detection
- Example of Incremental PCA
- Example of an Autoencoder with Keras
Running any example of HyperStream requires a MongoDB server. The configuration
of the host and ports of the MongoDB server can be changed in the file
hyperstream_config.json if needed.
To download the code and install the requirements ussing virtualenvironment just do the following:
git clone git@github.com:IRC-SPHERE/HyperStreamOnlineLearning.git
cd HyperStreamOnlineLearning
virtualenv venv
. venv/bin/activate
pip install -r requirements.txtIf you want to run the examples with Keras you will need to install some additional dependences. Once the previous requirements have been installed you can install the rest with the following command:
pip install -r keras_requirements.txtOnce the MongoDB server is up and running and you have installed all the Python requirements you can try to run the some fo the following examples:
To test if the code is working you can run a nosetest
nosetestYou should get something of the style
.
----------------------------------------------------------------------
Ran 1 testin 0.585s
OKThe following code should finish with the scores of a model trained on Iris dataset.
python example_classifier.py --dataset iris --classifier SGDClassifier --epochs 20 --seed 42At the end of the training you should see the test scores during the training for each epoch
Testscoresperepochduringtraining
[ 0.590.650.680.710.720.720.650.730.690.720.710.730.720.720.720.720.720.760.750.77]There is an additional example using Keras to specify Multilayer Perceptrons or Logistic regression. To run the example use these steps
python example_classifier_keras.py --dataset digits --classifier mlp30ds40m --epochs 20 --seed 42At the end of the training you should see the test scores during the training for each epoch
[ 0.480.750.840.890.890.90.910.910.920.910.920.940.930.940.930.930.940.940.950.94]Example of a model that trains only with the input space and predicts if the test data has been drawn from the same distribution. In this case using a Multivariate-Gaussian to estimate the density of the training data.
python example_anomalies.py --dataset iris --model Gaussian --epochs 1 --seed 42 -b 2At the end of the training you should see the test scores during the training for each epoch
[ nannannan0.920.930.570.520.910.810.410.840.530.770.880.950.790.580.840.690.820.630.550.990.90.890.650.610.830.870.860.780.750.740.660.840.920.810.81]python example_incremental_pca.py --dataset digits --components 10 --epochs 10 --seed 42 -b 100At the end of the training you should see the mean squared error of the reconstruction using the principal components of the PCA.
Testscoresperminibatch (cyclic)
[[ 5.85.115.545.335.595.085.355.145.045.184.795.425.245.485.065.335.135.015.24.765.435.25.455.095.365.064.995.264.735.415.225.45.125.355.084.935.294.735.445.155.375.155.355.084.945.274.775.435.135.375.265.235.074.945.294.785.415.135.355.275.245.064.935.284.835.395.185.285.275.285.034.945.284.845.435.145.255.35.265.064.895.34.855.45.175.215.325.235.085.04]]python example_autoencoder_keras.py --dataset digits --architecture auto30ns10ns2ns_10ns30ns --epochs 100 --seed 42 -b 10 --learning-rate 0.1Will output the following
_________________________________________________________________Layer (type) OutputShapeParam# [20/9638]=================================================================dense_1 (Dense) (None, 30) 1950_________________________________________________________________batch_normalization_1 (Batch (None, 30) 120_________________________________________________________________activation_1 (Activation) (None, 30) 0_________________________________________________________________dense_2 (Dense) (None, 10) 310_________________________________________________________________batch_normalization_2 (Batch (None, 10) 40_________________________________________________________________activation_2 (Activation) (None, 10) 0_________________________________________________________________dense_3 (Dense) (None, 2) 22_________________________________________________________________batch_normalization_3 (Batch (None, 2) 8_________________________________________________________________activation_3 (Activation) (None, 2) 0=================================================================Totalparams: 2,450Trainableparams: 2,366Non-trainableparams: 84_________________________________________________________________None_________________________________________________________________Layer (type) OutputShapeParam#=================================================================dense_4 (Dense) (None, 10) 30_________________________________________________________________batch_normalization_4 (Batch (None, 10) 40_________________________________________________________________activation_4 (Activation) (None, 10) 0_________________________________________________________________dense_5 (Dense) (None, 30) 330_________________________________________________________________batch_normalization_5 (Batch (None, 30) 120_________________________________________________________________activation_5 (Activation) (None, 30) 0_________________________________________________________________dense_6 (Dense) (None, 64) 1984=================================================================Totalparams: 2,504Trainableparams: 2,424Non-trainableparams: 80_________________________________________________________________None_________________________________________________________________Layer (type) OutputShapeParam# =================================================================sequential_1 (Sequential) (None, 2) 2450_________________________________________________________________sequential_2 (Sequential) (None, 64) 2504=================================================================Totalparams: 4,954Trainableparams: 4,790Non-trainableparams: 164_________________________________________________________________None2017-12-0415:49:37.732891: Itensorflow/core/platform/cpu_feature_guard.cc:137] YourCPUsupportsinstructionsthatthisTensorFlowbinarywasnotcompiledtouse: SSE4.1SSE4.2AVXTestscoresperminibatch (cyclic)
[[ 65.9658.5660.33 ..., 13.5410.8912.94]]