4

I am currently trying train a regression network using keras. To ensure I proper training I've want to train using crossvalidation.

The Problem is that it seems that keras don't have any functions supporting crossvalidation or do they?

The only solution I seemed to have found is to use scikit test_train_split and run a model.fit for for each k fold manually. Isn't there a already an integrated solutions for this, rather than manually doing it ?

0

2 Answers 2

2

Nope... That seem to be the solution. (Of what I know of.)

Sign up to request clarification or add additional context in comments.

Comments

1

There is a scikit learn wrapper for Keras that will help you do this easily: https://keras.io/scikit-learn-api/

I recommend reading Dr. Jason Brownlee's example: https://machinelearningmastery.com/regression-tutorial-keras-deep-learning-library-python/

 def baseline_model(): # create model model = Sequential() model.add(Dense(13, input_dim=13, kernel_initializer='normal', activation='relu')) model.add(Dense(1, kernel_initializer='normal')) # Compile model model.compile(loss='mean_squared_error', optimizer='adam') return model estimator = KerasRegressor(build_fn=wider_model, nb_epoch=100, batch_size=5, verbose=0) kfold = KFold(n_splits=10, random_state=seed) results = cross_val_score(pipeline, X, Y, cv=kfold) 

1 Comment

This only works for X being 2-dimensional, and not 3-dimensional such as for LSTM. ref

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.