Predict on fixed set - #53
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a “predict on a fixed set” workflow to the KRR CLI by appending a separate JSONL of unlabeled molecules to the dataset tail, ensuring they’re predicted while excluding them from holdout residual/metric calculations.
Changes:
- Add
--predictCLI option that appends an unlabeled (NaN label) prediction set and writes predictions back to the JSONL. - Track appended prediction rows (
n_predict) and exclude them from holdout residuals and reported test metrics. - Store reconstructed absolute holdout predictions to support writing prediction-tail outputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/nablachem/krr/krr.py |
Tracks prediction-tail rows, reconstructs absolute predictions, and excludes appended rows from residuals/metrics. |
src/nablachem/krr/dataset.py |
Adds predict_path support to append prediction molecules and a writer to emit predictions back to JSONL. |
src/nablachem/krr/cli.py |
Adds --predict option and writes prediction-tail outputs using the largest trained model. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+184
to
+186
| # Count appended prediction rows at the holdout tail. | ||
| self._n_predict = getattr(self.dataset, "n_predict", 0) | ||
|
|
Comment on lines
+528
to
+536
| # Exclude appended prediction rows from residuals and metrics. | ||
| n_real = len(self._y_holdout) - self._n_predict | ||
| for ntrain, preds in model_preds.items(): | ||
| pred = np.concatenate(preds, axis=0) | ||
| y_test = y_tests[ntrain] | ||
|
|
||
| # Reconstruct absolute predictions in original units. | ||
| self.holdout_predictions[ntrain] = pred + shifts[ntrain] + detrends[ntrain] | ||
|
|
Comment on lines
+258
to
+266
| # Write absolute predictions back into the prediction file. | ||
| if predict_path is not None and ds.n_predict > 0: | ||
| trained_sizes = [k for k in autokrr.holdout_predictions if k > 1] | ||
| if not trained_sizes: | ||
| error("No trained model available to predict with") | ||
| ntrain = max(trained_sizes) | ||
| n_real = len(autokrr._y_holdout) - autokrr._n_predict | ||
| predictions = autokrr.holdout_predictions[ntrain][n_real:] | ||
| info("Writing predictions", ntrain=ntrain, n_predict=ds.n_predict) |
Comment on lines
192
to
196
| utils.error( | ||
| "Max training size too large", | ||
| max_training_size=max_training_size, | ||
| total_molecules=total_molecules, | ||
| total_molecules=labeled_molecules, | ||
| ) |
Comment on lines
+472
to
+475
| for record, pred in zip(self.predict_records, predictions): | ||
| out = dict(record) | ||
| out[column] = None if np.isnan(pred) else float(pred) | ||
| f.write(json.dumps(out) + "\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.