Skip to content

Commit

Permalink
Merge pull request #44 from Techtonique/confsims
Browse files Browse the repository at this point in the history
Conformal simulations
  • Loading branch information
thierrymoudiki authored Apr 30, 2024
2 parents b99ae8e + 517e004 commit 0e6ffef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions nnetsauce/predictioninterval/predictioninterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def fit(self, X, y):

if self.method == "splitconformal":

n_samples_calibration = X_calibration.shape[0]
q = (self.level/100)*(1 + 1/n_samples_calibration)
n_samples_calibration = X_calibration.shape[0]
self.obj.fit(X_train, y_train)
preds_calibration = self.obj.predict(X_calibration)
self.calibrated_residuals_ = y_calibration - preds_calibration
Expand All @@ -97,12 +96,10 @@ def fit(self, X, y):
self.scaled_calibrated_residuals_ = self.calibrated_residuals_scaler_.fit_transform(self.calibrated_residuals_.reshape(-1, 1)).ravel()
try:
# numpy version >= 1.22
self.quantile_ = np.quantile(a = absolute_residuals, q = q,
method="higher")
self.quantile_ = np.quantile(a = absolute_residuals, q = self.level/100, method="higher")
except:
# numpy version < 1.22
self.quantile_ = np.quantile(a = absolute_residuals, q = q,
interpolation="higher")
self.quantile_ = np.quantile(a = absolute_residuals, q = self.level/100, interpolation="higher")


if self.method == "localconformal":
Expand All @@ -113,8 +110,7 @@ def fit(self, X, y):
self.icp_ = IcpRegressor(nc)
self.icp_.fit(X_train, y_train)
self.icp_.calibrate(X_calibration, y_calibration)
preds_calibration = self.icp_.predict(X_calibration)
print(f"\n\n preds_calibration: \n {preds_calibration} \n\n")
preds_calibration = self.icp_.predict(X_calibration)
self.calibrated_residuals_ = y_calibration - preds_calibration
absolute_residuals = np.abs(self.calibrated_residuals_)
self.calibrated_residuals_scaler_ = StandardScaler(with_mean=True, with_std=True)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from codecs import open
from os import path

__version__ = '0.19.0'
__version__ = '0.20.0'

# get the dependencies and installs
here = path.abspath(path.dirname(__file__))
Expand Down

0 comments on commit 0e6ffef

Please sign in to comment.