Cross-validation error as PySR objective function? #659
-
Hello. As the title suggests, I am trying to write a custom objective function based on the cross-validation error. However, I am not really well-versed in Julia. This is my amateur attempt at writing a cross-validation error-based objective function:
I am getting a Julia error if I use this code. It appears to be related to accessing invalid index ranges. Is there already a code for some sort of cross-validation error already available here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
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:
(And, by the way, Julia indexes with column-major order, so you would write the row first, feature second, like
X[:, train_idx]
)