-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Techtonique/prediction-interval
Prediction intervals for Split Conformal for LSBoost Regression
- Loading branch information
Showing
18 changed files
with
2,952 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import subprocess | ||
import sys | ||
|
||
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"]) | ||
|
||
import mlsauce as ms | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from sklearn.datasets import fetch_california_housing, load_diabetes | ||
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score | ||
from time import time | ||
from os import chdir | ||
from sklearn import metrics | ||
|
||
# ridge | ||
|
||
print("\n") | ||
print("ridge -----") | ||
print("\n") | ||
|
||
|
||
dataset = fetch_california_housing() | ||
X = dataset.data | ||
y = dataset.target | ||
# split data into training test and test set | ||
np.random.seed(15029) | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, | ||
test_size=0.2) | ||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9) | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal coverage 1: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="bootstrap") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal bootstrap coverage 1: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="kde") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal kde coverage 1: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
dataset = load_diabetes() | ||
X = dataset.data | ||
y = dataset.target | ||
# split data into training test and test set | ||
np.random.seed(15029) | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, | ||
test_size=0.2) | ||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9) | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="bootstrap") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal bootstrap coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="kde") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal kde coverage 2: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
|
||
# lasso | ||
|
||
print("\n") | ||
print("lasso -----") | ||
print("\n") | ||
|
||
|
||
dataset = fetch_california_housing() | ||
X = dataset.data | ||
y = dataset.target | ||
# split data into training test and test set | ||
np.random.seed(15029) | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, | ||
test_size=0.2) | ||
|
||
obj = ms.LSBoostRegressor(n_estimators=50, solver="lasso", col_sample=0.9, row_sample=0.9) | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal coverage 3: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(n_estimators=50, solver="lasso", col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="bootstrap") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal bootstrap coverage 3: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(n_estimators=50, solver="lasso", col_sample=0.9, row_sample=0.9, | ||
replications=50, | ||
type_pi="kde") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal kde coverage 3: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
dataset = load_diabetes() | ||
X = dataset.data | ||
y = dataset.target | ||
# split data into training test and test set | ||
np.random.seed(15029) | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, | ||
test_size=0.2) | ||
|
||
obj = ms.LSBoostRegressor(n_estimators=50, solver="lasso", reg_lambda=0.002, | ||
col_sample=0.9, row_sample=0.9) | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal coverage 4: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(n_estimators=10, solver="lasso", col_sample=0.9, row_sample=0.9, | ||
replications=50, reg_lambda=0.003, dropout=0.4, | ||
type_pi="bootstrap") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal bootstrap coverage 4: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
||
|
||
obj = ms.LSBoostRegressor(n_estimators=10, solver="lasso", col_sample=0.9, row_sample=0.9, | ||
replications=50, reg_lambda=0.001, dropout=0.4, | ||
type_pi="kde") | ||
print(obj.get_params()) | ||
start = time() | ||
obj.fit(X_train, y_train) | ||
print(time()-start) | ||
start = time() | ||
preds = obj.predict(X_test, return_pi=True, | ||
method="splitconformal") | ||
print(time()-start) | ||
print(f"splitconformal kde coverage 4: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}") | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
The MIT License (MIT) | ||
|
||
nonconformist package: | ||
Copyright (c) 2015 Henrik Linusson | ||
|
||
Other extensions: | ||
Copyright (c) 2019 Yaniv Romano | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
docstring | ||
""" | ||
|
||
# Authors: Henrik Linusson | ||
# Yaniv Romano modified np.py file to include CQR | ||
# T. Moudiki modified __init__.py to import classes | ||
|
||
#__version__ = '2.1.0' | ||
|
||
from .nc import AbsErrorErrFunc, QuantileRegErrFunc, RegressorNc, RegressorNormalizer | ||
from .cp import IcpRegressor | ||
from .base import RegressorAdapter | ||
|
||
__all__ = ["AbsErrorErrFunc", "QuantileRegErrFunc", "RegressorAdapter", "RegressorNc", "RegressorNormalizer", "IcpRegressor"] |
Oops, something went wrong.