Skip to content

Predict on fixed set - #53

Merged
ferchault merged 2 commits into
mainfrom
feature/pred
Jul 21, 2026
Merged

Predict on fixed set#53
ferchault merged 2 commits into
mainfrom
feature/pred

Conversation

@ferchault

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 21, 2026 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --predict CLI 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 thread src/nablachem/krr/krr.py Outdated
Comment on lines +184 to +186
# Count appended prediction rows at the holdout tail.
self._n_predict = getattr(self.dataset, "n_predict", 0)

Comment thread src/nablachem/krr/krr.py
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 thread src/nablachem/krr/cli.py Outdated
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)
Copilot AI review requested due to automatic review settings July 21, 2026 18:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/nablachem/krr/krr.py
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")
@ferchault
ferchault merged commit 646c675 into main Jul 21, 2026
6 checks passed
@ferchault
ferchault deleted the feature/pred branch July 21, 2026 18:11
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

Successfully merging this pull request may close these issues.

2 participants