machine learning - Even setting random seed sequential model in keras returns differnt results -
can me understand why model not give reproducible results? changes accuracy values test sets , other validation sets using, each time run it. using defined seed. can not understand why happening.
below part of code:
np.random.seed(7) # create model def create_model(neurons=190, init_mode='normal', activation='relu', inputdim=8040, dropout_rate=0.8, learn_rate=0.001, momentum=0.7, weight_constraint=5): model = sequential() model.add(dense(neurons, input_dim=inputdim, kernel_initializer=init_mode, activation=activation, kernel_constraint=maxnorm(weight_constraint), kernel_regularizer=regularizers.l2(0.002))) model.add(dense(1, activation='sigmoid')) optimizer = rmsprop(lr=learn_rate) # compile model model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy']) model = create_model() seed = 7 # define k-fold cross validation test harness kfold = stratifiedkfold(n_splits=3, shuffle=true, random_state=seed) cvscores = [] train, test in kfold.split(x_train, y_train): print("train:", train, "validation:", test) # fit model history = model.fit(x_train, y_train, epochs=40, batch_size=50, validation_data=(x_test, y_test), verbose=0) i appreciate comments on it.
your random seed fixing cross-validation split not model weight initialization, specify in create_model when set keyword "init_mode=normal".
you try setting rng seed prior calling create_model depending on how keras generating random numbers, may need resort using custom initializer consistent results.
seed configuration dependent on several other factors, including keras backend using (theano vs. tensorflow) , python version using. see this github issue additional details.
Comments
Post a Comment