Demo entry 6322283

aaaa

   

Submitted by anonymous on Nov 12, 2016 at 02:06
Language: Python. Code size: 1.5 kB.

def model2(**opt):
    batch_size = opt.get('batch_size', 32)
    nb_epoch = opt.get('nb_epoch', 90)
    cw = opt.get('cw', None)

    m = Sequential()
    m.add(Dense(256, input_dim=8, init='uniform', activation='tanh'))
    m.add(Dropout(0.2))
    m.add(Dense(256, init='uniform', activation='tanh'))
    m.add(Dropout(0.2))
    #m.add(Dense(256, init='uniform', activation='relu'))
    #m.add(Dropout(0.2))
    m.add(Dense(nb_classes, init='uniform', activation='softmax'))

    if cw is None:
        cweight = None
    else:
        cweight = calc_class_weight(X_train, y_train, cw)
    
    #m.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    #sgd = SGD(lr=1.0)
    #m.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
    #m.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    rms = RMSprop()
    #m.compile(loss='categorical_crossentropy', optimizer=rms, metrics=['accuracy'])
    #m.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
    m.compile(loss='categorical_crossentropy', optimizer=rms)

    fmon = FitMonitor(thresh=0.02, minacc=0.99, filename="model2.h5")
    h = m.fit(
        X_train,
        Y_train,
        batch_size=batch_size,
        nb_epoch=nb_epoch,
        class_weight=cweight,
        shuffle=True,
        verbose=1,
        validation_data=(X_test, Y_test),
        #callbacks = [fmon]
    )
    
    show_scores(m, h)
    return m,h

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).