fchollet / deep-learning-with-python-notebooks

Jupyter notebooks for the code samples of the book "Deep Learning with Python"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug on code for k-fold cross val

jboverio opened this issue · comments

This code (k-fold cross val) misses a parenthesis on np.concatenate:

'''k = 3
num_validation_samples = len(data) // k
np.random.shuffle(data)
validation_scores = []
for fold in range(k):
validation_data = data[num_validation_samples * fold: ❶
num_validation_samples * (fold + 1)] ❶
training_data = np.concatenate( ❷
data[:num_validation_samples * fold], ❷
data[num_validation_samples * (fold + 1):]) ❷
model = get_model() ❸
model.fit(training_data, ...)
validation_score = model.evaluate(validation_data, ...)
validation_scores.append(validation_score)
validation_score = np.average(validation_scores) ❹
model = get_model() ❺
model.fit(data, ...) ❺
test_score = model.evaluate(test_data, ...) '''

The previous code (held out validation) was correct, the k-fold code misses a "(" and ")", the correct code should look like:

'''training_data = np.concatenate( (
data[:num_validation_samples * fold], ❷
data[num_validation_samples * (fold + 1):]) ) ❷'''

As documentation for np.concatenate states:

'''a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
p.concatenate((a, b), axis=None)'''

Kind regards

commented

Also would be great to make clear on the code too that it is supressing the k-fold for the labels