def modelo2(train, test, coluna): X_train = train.drop('default payment next month', axis=1) Y_train = train['default payment next month'] X_test = test.drop('default payment next month', axis=1) Y_test = test['default payment next month'] tamanho = len(X_train.columns) + 1 X_train = X_train.values Y_train = Y_train.values X_test = X_test.values Y_test = Y_test.values salvar = pandas.read_csv('resultados_stepwise.csv') i = len(salvar.index) + 1 layer_1 = 46 layer_2 = 12 #se zero, comentar a linha do layer_2 rate = 0.01 epoch = 200 #50 batch = 128 decay = 1e-12 #decay = 0.0 drop = 0.5 #se 0, comentar a linha do dropout model = load_model('my_model.h5') predictions = model.predict(X_test) predictions = pandas.DataFrame(predictions, columns=['SCORE']) s = pandas.DataFrame(Y_test, columns=['CLASSE']) x = predictions.join(s) ks_max = teste_ks.KS(x) salvar.loc[i] = [ ks_max, layer_1, layer_2, rate, epoch, batch, decay, drop, coluna ] salvar.to_csv("resultados_stepwise.csv", index=False) return ks_max
def modelo(train, test, coluna): ### X_train = train.drop('default payment next month', axis=1) Y_train = train['default payment next month'] X_test = test.drop('default payment next month', axis=1) Y_test = test['default payment next month'] tamanho = len(X_train.columns) + 1 X_train = X_train.values Y_train = Y_train.values X_test = X_test.values Y_test = Y_test.values ## sm = SMOTE(kind='regular') X_resampled, Y_resampled = sm.fit_sample(X_train, Y_train) layer_1 = 46 layer_2 = 12 #se zero, comentar a linha do layer_2 rate = 0.01 epoch = 200 #50 batch = 128 decay = 1e-12 #decay = 0.0 drop = 0.5 #se 0, comentar a linha do dropout salvar = pandas.read_csv('resultados_stepwise.csv') i = len(salvar.index) + 1 # Model Creation, 1 input layer, 1 hidden layer and 1 exit layter model = Sequential() model.add(Dense(layer_1, input_dim=tamanho - 1, init='uniform')) model.add(Activation('relu')) model.add(Dropout(drop)) model.add(Dense(layer_2, init='uniform')) # activation='relu' model.add(Activation('relu')) model.add(Dropout(drop)) #model.add(Dense(60, init='uniform')) #model.add(Activation('relu')) model.add(Dense(1, init='uniform')) model.add(Activation('sigmoid')) #activation='relu' opt = keras.optimizers.SGD(lr=rate, decay=decay) # Compile model model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy']) # creating .fit model.fit(X_resampled, Y_resampled, nb_epoch=epoch, batch_size=batch, verbose=0) scores = model.evaluate(X_test, Y_test) print() print("%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100)) # predicting model predictions = model.predict(X_test) predictions = pandas.DataFrame(predictions, columns=['SCORE']) s = pandas.DataFrame(Y_test, columns=['CLASSE']) x = predictions.join(s) ks_max = teste_ks.KS(x) salvar.loc[i] = [ ks_max, layer_1, layer_2, rate, epoch, batch, decay, drop, coluna ] salvar.to_csv("resultados_stepwise.csv", index=False) return ks_max