コード例 #1
0
    fc1 = PReLU()(fc1)
    fc1 = BatchNormalization()(fc1)
    fc1 = Dropout(0.2)(fc1)


    outputs = Dense(1,activation='sigmoid')(fc1)
    model = Model(input=inputs, output=outputs)
    
    model.compile(
                optimizer='adam',
                loss = 'binary_crossentropy',
              )
    return model

class NN(BaseEstimator):
    def __init__(self,input_shape,hidden=128):
        self.input_shape = input_shape
        self.hidden = hidden
    def fit(self,X,y):
        model = build_model(maxlen=self.input_shape,hidden=self.hidden)
        model.fit(X,y,nb_epoch=250,batch_size=128,shuffle=True,verbose=0)
        self.model=model
    def predict_proba(self,X):
        y_p = self.model.predict(X,batch_size=1024).ravel()
        y_p_inv= np.ones(y_p.shape[0])-y_p
        y_p = np.hstack([y_p_inv.reshape(-1,1),y_p.reshape(-1,1)])
        return y_p

clf = NN(X.shape[1],128)
make_mf_classification(X ,y, clf, X_t, n_folds=5,seed=seed,nb_epoch=1,max_features=1.0,name='nn_2',path=path)
コード例 #2
0
class NN(BaseEstimator):
    def __init__(self, input_shape, hidden=128):
        self.input_shape = input_shape
        self.hidden = hidden

    def fit(self, X, y):
        model = build_model(maxlen=self.input_shape, hidden=self.hidden)
        model.fit(X, y, epochs=250, batch_size=128, shuffle=True, verbose=1)
        self.model = model

    def predict_proba(self, X):
        y_p = self.model.predict(X, batch_size=1024).ravel()
        y_p_inv = np.ones(y_p.shape[0]) - y_p
        y_p = np.hstack([y_p_inv.reshape(-1, 1), y_p.reshape(-1, 1)])
        return y_p


scaler = MinMaxScaler()
scaler.fit(X)
clf = NN(X.shape[1], 128)
make_mf_classification(scaler.transform(X),
                       y,
                       clf,
                       scaler.transform(X_t),
                       n_folds=5,
                       seed=seed,
                       nb_epoch=1,
                       max_features=1.0,
                       name='nn_3',
                       path=path)