From 5b67c4c4ec36aa0ad8425602efd6a843a9a8c8c6 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 15 Aug 2024 11:07:32 +0200 Subject: [PATCH 1/2] Reorganise files --- .gitignore | 4 ++-- book/content | 2 +- .../python_files}/_generate_predictions.py | 12 ++++++------ .../python_files}/build_calibration_curve.py | 4 ++-- .../python_files}/different_calibration_curves.py | 10 +++++----- pixi.toml | 8 ++++---- tests/check_generated_predictions.py | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) rename {python_files => content/python_files}/_generate_predictions.py (75%) rename {python_files => content/python_files}/build_calibration_curve.py (98%) rename {python_files => content/python_files}/different_calibration_curves.py (95%) diff --git a/.gitignore b/.gitignore index e76af46..c369a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -78,8 +78,8 @@ jupyterlite_contents *.egg-info # generate predictions -python_files/predictions +content/predictions # jupyter-book build book/_build -python_files/*.ipynb +content/notebooks diff --git a/book/content b/book/content index 8394e1e..efcdaa6 120000 --- a/book/content +++ b/book/content @@ -1 +1 @@ -../python_files \ No newline at end of file +../content \ No newline at end of file diff --git a/python_files/_generate_predictions.py b/content/python_files/_generate_predictions.py similarity index 75% rename from python_files/_generate_predictions.py rename to content/python_files/_generate_predictions.py index 12991fd..7997979 100644 --- a/python_files/_generate_predictions.py +++ b/content/python_files/_generate_predictions.py @@ -1,7 +1,7 @@ # %% from pathlib import Path -Path.mkdir(Path.cwd() / "predictions", exist_ok=True) +Path.mkdir(Path.cwd() / ".." / "predictions", exist_ok=True) # %% import numpy as np @@ -12,7 +12,7 @@ n_samples=100_000, class_sep=0.5, random_state=0 ) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0) -np.save("./predictions/y_true.npy", y_test) +np.save("../predictions/y_true.npy", y_test) # %% from sklearn.linear_model import LogisticRegression @@ -24,7 +24,7 @@ y_pred = model.predict_proba(X_test)[:, 1] # %% -np.save("./predictions/y_prob_1.npy", y_pred) +np.save("../predictions/y_prob_1.npy", y_pred) # %% from scipy.special import expit @@ -33,7 +33,7 @@ y_pred = expit(10 * (y_pred - 0.5)) # %% -np.save("./predictions/y_prob_2.npy", y_pred) +np.save("../predictions/y_prob_2.npy", y_pred) # %% @@ -42,7 +42,7 @@ y_pred = (y_pred - y_pred.min()) / (y_pred.max() - y_pred.min()) # %% -np.save("./predictions/y_prob_3.npy", y_pred) +np.save("../predictions/y_prob_3.npy", y_pred) # %% y_pred = model.predict_proba(X_test)[:, 1] @@ -50,4 +50,4 @@ y_pred = (y_pred - y_pred.min()) / (y_pred.max() - y_pred.min()) # %% -np.save("./predictions/y_prob_4.npy", y_pred) +np.save("../predictions/y_prob_4.npy", y_pred) diff --git a/python_files/build_calibration_curve.py b/content/python_files/build_calibration_curve.py similarity index 98% rename from python_files/build_calibration_curve.py rename to content/python_files/build_calibration_curve.py index 1c88f8f..44ca1e7 100644 --- a/python_files/build_calibration_curve.py +++ b/content/python_files/build_calibration_curve.py @@ -29,8 +29,8 @@ # %% import numpy as np -y_true = np.load("./predictions/y_true.npy") -y_prob = np.load("./predictions/y_prob_2.npy") +y_true = np.load("../predictions/y_true.npy") +y_prob = np.load("../predictions/y_prob_2.npy") # %% y_true diff --git a/python_files/different_calibration_curves.py b/content/python_files/different_calibration_curves.py similarity index 95% rename from python_files/different_calibration_curves.py rename to content/python_files/different_calibration_curves.py index 6764ac1..741a056 100644 --- a/python_files/different_calibration_curves.py +++ b/content/python_files/different_calibration_curves.py @@ -25,7 +25,7 @@ # %% import numpy as np -y_true = np.load("./predictions/y_true.npy") +y_true = np.load("../predictions/y_true.npy") y_true # %% [markdown] @@ -34,7 +34,7 @@ # sets of predictions of probabilities estimated by different models. # %% -y_proba = np.load("./predictions/y_prob_1.npy") +y_proba = np.load("../predictions/y_prob_1.npy") y_proba # %% [markdown] @@ -76,7 +76,7 @@ # We now repeat the same analysis for the other sets of predictions. # %% -y_proba = np.load("./predictions/y_prob_2.npy") +y_proba = np.load("../predictions/y_prob_2.npy") disp = CalibrationDisplay.from_predictions(y_true, y_proba, **params) _ = disp.ax_.set( title="Uncalibrated model", @@ -119,7 +119,7 @@ # Let's use the same approach to analyze some other typical calibration curves. # %% -y_proba = np.load("./predictions/y_prob_3.npy") +y_proba = np.load("../predictions/y_prob_3.npy") disp = CalibrationDisplay.from_predictions(y_true, y_proba, **params) disp.ax_.axvline(0.5, color="tab:orange", label="Estimated probability = 0.5") disp.ax_.legend() @@ -147,7 +147,7 @@ # Let's check the last set of predictions. # %% -y_proba = np.load("./predictions/y_prob_4.npy") +y_proba = np.load("../predictions/y_prob_4.npy") disp = CalibrationDisplay.from_predictions(y_true, y_proba, **params) disp.ax_.axvline(0.5, color="tab:orange", label="Estimated probability = 0.5") disp.ax_.legend() diff --git a/pixi.toml b/pixi.toml index c15c5be..4c16afb 100644 --- a/pixi.toml +++ b/pixi.toml @@ -7,10 +7,10 @@ channels = ["conda-forge"] platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"] [tasks] -generate-predictions = { cmd = "python _generate_predictions.py", cwd = "python_files" } -build-calibration-curve = { cmd = "ipython build_calibration_curve.py", cwd = "python_files" } +generate-predictions = { cmd = "python _generate_predictions.py", cwd = "content/python_files" } +build-calibration-curve = { cmd = "ipython build_calibration_curve.py", cwd = "content/python_files" } check-generated-predictions = { cmd = "python check_generated_predictions.py", cwd = "tests" } -different-calibration-curves = { cmd = "ipython different_calibration_curves.py", cwd = "python_files" } +different-calibration-curves = { cmd = "ipython different_calibration_curves.py", cwd = "content/python_files" } [dependencies] jupyterlab = ">=4.2.4,<5" @@ -32,7 +32,7 @@ black = "*" jupyter-book = "*" [feature.doc.tasks] -convert-to-notebooks = { cmd = "jupytext --to notebook --execute python_files/*.py" } +convert-to-notebooks = { cmd = "jupytext --to notebook --execute ./content/python_files/*.py && mkdir -p ./content/notebooks && mv ./content/python_files/*.ipynb ./content/notebooks" } build-book = { cmd = "jupyter-book build book", depends-on = ["convert-to-notebooks"] } [environments] diff --git a/tests/check_generated_predictions.py b/tests/check_generated_predictions.py index 189aa0d..1e79a21 100644 --- a/tests/check_generated_predictions.py +++ b/tests/check_generated_predictions.py @@ -1,7 +1,7 @@ # %% from pathlib import Path -path_to_predictions = Path(Path.cwd() / ".." / "python_files" / "predictions") +path_to_predictions = Path(Path.cwd() / ".." / "content" / "predictions") assert path_to_predictions.exists() # %% From 2a45c636d260bc6ae3d7a0c9ab456159f3e0ee55 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Thu, 15 Aug 2024 11:08:38 +0200 Subject: [PATCH 2/2] iter --- content/python_files/build_calibration_curve.py | 2 +- content/python_files/different_calibration_curves.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/python_files/build_calibration_curve.py b/content/python_files/build_calibration_curve.py index 44ca1e7..be5307e 100644 --- a/content/python_files/build_calibration_curve.py +++ b/content/python_files/build_calibration_curve.py @@ -20,7 +20,7 @@ from IPython import get_ipython ipython = get_ipython() -ipython.run_line_magic("run", "_generate_predictions.py") +ipython.run_line_magic("run", "../python_files/_generate_predictions.py") # %% [markdown] # diff --git a/content/python_files/different_calibration_curves.py b/content/python_files/different_calibration_curves.py index 741a056..25c2e04 100644 --- a/content/python_files/different_calibration_curves.py +++ b/content/python_files/different_calibration_curves.py @@ -16,7 +16,7 @@ from IPython import get_ipython ipython = get_ipython() -ipython.run_line_magic("run", "_generate_predictions.py") +ipython.run_line_magic("run", "../python_files/_generate_predictions.py") # %% [markdown] #