Example #1
0
def auto_encode(x, y):
    from sknn import ae, mlp

    # Initialize auto-encoder for unsupervised learning.
    myae = ae.AutoEncoder(
        layers=[ae.Layer("Tanh", units=8),
                ae.Layer("Sigmoid", units=4)],
        learning_rate=0.002,
        n_iter=10)

    # Layerwise pre-training using only the input data.
    myae.fit(x)

    # Initialize the multi-layer perceptron with same base layers.
    mymlp = mlp.Regressor(layers=[
        mlp.Layer("Tanh", units=8),
        mlp.Layer("Sigmoid", units=4),
        mlp.Layer("Linear")
    ])

    # Transfer the weights from the auto-encoder.
    myae.transfer(mymlp)
    # Now perform supervised-learning as usual.
    mymlp.fit(x, y)
    return mymlp
Example #2
0
def autoEncoderOptimization(data):
    rbm = ae.AutoEncoder(layers=[
        ae.Layer("Tanh", units=300),
        ae.Layer("Sigmoid", units=200),
        ae.Layer("Tanh", units=100)
    ],
                         learning_rate=0.002,
                         n_iter=10)

    rbm.fit(data["train"])

    model = Classifier(layers=[
        Layer("Tanh", units=300),
        Layer("Sigmoid", units=200),
        Layer("Tanh", units=100),
        Layer("Rectifier", units=100),
        Layer("Rectifier", units=50),
        Layer("Softmax")
    ], )

    rbm.transfer(model)

    model.fit(data["train"], data["label"])

    prediction = model.predict(data["train"])

    print accuracy_score(data["label"], prediction)
Example #3
0
traindata = traindata[:1000]
traindata = traindata.values
# train split uses default gini node, split using train_test_split

X = traindata[1:, 1:]
Y = traindata[1:, 0]
cv = train_test_split(X, Y, test_size=.33, random_state=20)
X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                    Y,
                                                    test_size=.33,
                                                    random_state=20)

#Finding the optimal component

AELayers = [
    ae.Layer("Sigmoid", units=1000),
    ae.Layer("Sigmoid", units=500),
    ae.Layer("Sigmoid", units=250)
]
NNLayers = [
    mlp.Layer("Sigmoid", units=1000),
    mlp.Layer("Sigmoid", units=500),
    mlp.Layer("Softmax", units=15)
]

##
##for each in complist:
##    comp = each
t0 = time.clock()

print("Time started")
nn = mlp.Classifier(layers=[
    mlp.Layer("Tanh", units=n_feat * 2 / 3),
    mlp.Layer("Sigmoid", units=n_feat * 1 / 3),
    mlp.Layer("Softmax", units=n_targets)
],
                    n_iter=50,
                    n_stable=10,
                    learning_rate=0.001,
                    valid_size=0.5,
                    verbose=1)

if PRETRAIN:
    from sknn import ae
    ae = ae.AutoEncoder(layers=[
        ae.Layer("Tanh", units=n_feat * 2 / 3),
        ae.Layer("Sigmoid", units=n_feat * 2 / 3)
    ],
                        learning_rate=0.002,
                        n_iter=10,
                        verbose=1)
    ae.fit(data_train)
    ae.transfer(nn)

nn.fit(data_train, labels_train)

from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix

expected = labels_test
predicted = net.predict(data_test)
Example #5
0
nn = mlp.Classifier(layers=[
    mlp.Layer("Tanh", units=n_feat / 8),
    mlp.Layer("Sigmoid", units=n_feat / 16),
    mlp.Layer("Softmax", units=n_targets)
],
                    n_iter=50,
                    n_stable=10,
                    learning_rate=0.002,
                    learning_rule="momentum",
                    valid_size=0.1,
                    verbose=1)

if PRETRAIN:
    from sknn import ae
    ae = ae.AutoEncoder(layers=[
        ae.Layer("Tanh", units=n_feat / 8),
        ae.Layer("Sigmoid", units=n_feat / 16)
    ],
                        learning_rate=0.002,
                        n_iter=10,
                        verbose=1)
    ae.fit(data_train)
    ae.transfer(nn)

nn.fit(data_train, labels_train)

from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix

expected = labels_test
predicted = nn.predict(data_test)
traindata = traindata[:1000]
traindata = traindata.values
# train split uses default gini node, split using train_test_split

X = traindata[1:, 1:]
Y = traindata[1:, 0]
cv = train_test_split(X, Y, test_size=.33, random_state=20)
X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                    Y,
                                                    test_size=.33,
                                                    random_state=20)

#Finding the optimal component

AELayers = [
    ae.Layer("Sigmoid", units=120),
    ae.Layer("Sigmoid", units=60),
    ae.Layer("Sigmoid", units=30)
]
NNLayers = [
    mlp.Layer("Sigmoid", units=120),
    mlp.Layer("Sigmoid", units=75),
    mlp.Layer("Softmax", units=5)
]

##
##for each in complist:
##    comp = each
t0 = time.clock()

print("Time started")