Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug on code for k-fold cross val #223

Open
jboverio opened this issue Jun 1, 2023 · 2 comments
Open

Bug on code for k-fold cross val #223

jboverio opened this issue Jun 1, 2023 · 2 comments

Comments

@jboverio
Copy link

jboverio commented Jun 1, 2023

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

@ifond
Copy link

ifond commented Jun 1, 2023 via email

@jboverio
Copy link
Author

jboverio commented Jun 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants