Skip to content

Cross-validation error as PySR objective function? #659

Answered by MilesCranmer
sbalasbas3 asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe just do it from the Python side? It should be faster too as then you aren't doing the split every single evaluation, but only once:

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=0)

model.fit(X_train, y_train)

train_loss = np.mean(np.square(y_train - model.predict(X_train, index=-1)))
test_loss = np.mean(np.square(y_test - model.predict(X_test, index=-1)))

(And, by the way, Julia indexes with column-major order, so you would write the row first, feature second, like X[:, train_idx])

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sbalasbas3
Comment options

Answer selected by sbalasbas3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion
2 participants