Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Apr 16, 2024
1 parent e326d78 commit 21b4771
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 236 deletions.
40 changes: 40 additions & 0 deletions examples/lsboost_regressor_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mlsauce as ms
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
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
Expand Down Expand Up @@ -219,3 +220,42 @@
print(time()-start)
print(f"splitconformal kde coverage 4: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")




#Load Boston housing dataset
data_url = "http://lib.stat.cmu.edu/datasets/boston"
raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)

X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
y = raw_df.values[1::2, 2]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=23)


obj = ms.LSBoostRegressor(n_estimators=50, solver="ridge", reg_lambda=0.002,
col_sample=0.8, row_sample=0.8)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(f"Elapsed: {time()-start}")
start = time()
preds = obj.predict(X_test, return_pi=True,
level = 90,
method="splitconformal")
print(time()-start)
print(f"splitconformal coverage 5: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")


obj = ms.LSBoostRegressor(n_estimators=50, solver="lasso", reg_lambda=0.002,
col_sample=0.8, row_sample=0.8)
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,
level = 90,
method="splitconformal")
print(time()-start)
print(f"splitconformal bootstrap coverage 5: {np.mean((preds.upper >= y_test)*(preds.lower <= y_test))}")
36 changes: 0 additions & 36 deletions mlsauce.egg-info/PKG-INFO

This file was deleted.

58 changes: 0 additions & 58 deletions mlsauce.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion mlsauce.egg-info/dependency_links.txt

This file was deleted.

1 change: 0 additions & 1 deletion mlsauce.egg-info/not-zip-safe

This file was deleted.

14 changes: 0 additions & 14 deletions mlsauce.egg-info/requires.txt

This file was deleted.

1 change: 0 additions & 1 deletion mlsauce.egg-info/top_level.txt

This file was deleted.

Loading

0 comments on commit 21b4771

Please sign in to comment.