In [287]:
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
from sklearn.datasets import make_multilabel_classification
from rgb_nn import RGB_NN
import time

In [3]:
def plot_multi_lables(X, y):
    pd.DataFrame(X).plot(x=0,y=1,kind='scatter', c=y[:,0]+(y[:,1]*2), cmap='cool')
    plt.show()

In [4]:
data = make_multilabel_classification(n_samples=1000, n_features=2, n_classes=2, n_labels=1, random_state=14)
plot_multi_lables(data[0],data[1])



In [5]:
from sklearn.neural_network import MLPClassifier
from sklearn import datasets, preprocessing
from sklearn.model_selection import train_test_split
import numpy as np

In [6]:
X = preprocessing.scale(data[0] ,axis=0)  
y = data[1]

In [7]:
plt.scatter(x = X[:,0], y = X[:,1], c = y[:,0])


Out[7]:
<matplotlib.collections.PathCollection at 0x114422240>

In [8]:
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.33, random_state=42)

In [295]:
nn = MLPClassifier(hidden_layer_sizes=(3), 
                   activation='logistic', 
                   learning_rate_init=0.1, 
                   max_iter=1, warm_start=True)

In [13]:
rgb = RGB_NN(server_loc='http://192.168.1.153:5000', scale=(-1.5,1.5))
rgb._dummy_api = True
# rgb._verbose = False
rgb._brightness = 0.15

In [289]:
%matplotlib


Using matplotlib backend: MacOSX

In [298]:
# Create new Figure and an Axes which fills it.
fig, ax = plt.subplots()

scat = ax.scatter(X_test[:,0],
                  X_test[:,1],
                  s=50)

def update(frame_number):
    
    nn.fit(X_train, y_train)
    prediction = nn.predict(X_test)
    y = prediction[:,0]+(prediction[:,1]*2)
    cm = [plt.cm.cool(n) for n in y/3]
    
    rgb.display_weights(nn)
    
    print(nn.score(X_test, y_test))
    
    scat.set_facecolors(cm)

animation = FuncAnimation(fig, update, interval=100, repeat=0, frames=20)
plt.show()


0.845454545455
0.848484848485
0.842424242424
0.845454545455
0.842424242424
0.827272727273
0.839393939394
0.827272727273
0.845454545455
0.842424242424
0.851515151515
0.833333333333
0.851515151515
0.854545454545
0.839393939394
0.839393939394
0.845454545455
0.833333333333
0.845454545455
0.842424242424
0.845454545455

In [299]:
nn.coefs_


Out[299]:
[array([[-5.36952356, -1.72024248,  5.10815695],
        [ 4.09068338,  1.9867092 , -2.09325361]]),
 array([[ 5.45190875,  3.53324708],
        [-8.59004428,  4.17241364],
        [ 5.39515024, -5.01913459]])]

In [ ]: