Skip to content

Commit

Permalink
add cross val. and lazy cross val. Pt.3
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Aug 4, 2024
1 parent 8b4b796 commit 7bb241c
Show file tree
Hide file tree
Showing 3 changed files with 483 additions and 0 deletions.
82 changes: 82 additions & 0 deletions examples/cross_val.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import unifiedbooster as ub
from sklearn.datasets import load_iris, load_breast_cancer, load_wine
from sklearn.model_selection import train_test_split
from sklearn.linear_model import ElasticNetCV
from sklearn.kernel_ridge import KernelRidge
from sklearn.metrics import accuracy_score
from time import time

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

dataset = load_breast_cancer()
X, y = dataset.data, dataset.target
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)

print("\n Example 1 -----")

res1 = ub.cross_val_optim(
X_train,
y_train,
X_test=None,
y_test=None,
model_type="lightgbm",
type_fit="classification",
scoring="accuracy",
n_estimators=100,
surrogate_obj=None,
cv=5,
n_jobs=None,
n_init=10,
n_iter=190,
abs_tol=1e-3,
verbose=2,
seed=123,
)
print(res1)

print("\n Example 2 -----")

res2 = ub.cross_val_optim(
X_train,
y_train,
X_test=X_test,
y_test=y_test,
model_type="lightgbm",
type_fit="classification",
scoring="accuracy",
n_estimators=100,
surrogate_obj=None,
cv=5,
n_jobs=None,
n_init=10,
n_iter=190,
abs_tol=1e-3,
verbose=2,
seed=123,
)
print(res2)

print("\n Example 3 -----")

res3 = ub.cross_val_optim(
X_train,
y_train,
X_test=X_test,
y_test=y_test,
model_type="lightgbm",
type_fit="classification",
scoring="accuracy",
n_estimators=100,
surrogate_obj=KernelRidge(),
cv=5,
n_jobs=None,
n_init=10,
n_iter=190,
abs_tol=1e-3,
verbose=2,
seed=123,
)
print(res3)
34 changes: 34 additions & 0 deletions examples/lazy_cross_val.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import unifiedbooster as ub
from sklearn.datasets import load_iris, load_breast_cancer, load_wine
from sklearn.model_selection import train_test_split
from sklearn.linear_model import ElasticNetCV
from sklearn.kernel_ridge import KernelRidge
from sklearn.metrics import accuracy_score
from time import time

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

dataset = load_iris()
X, y = dataset.data, dataset.target
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)

res3 = ub.lazy_cross_val_optim(
X_train,
y_train,
X_test=X_test,
y_test=y_test,
model_type="lightgbm",
type_fit="classification",
scoring="accuracy",
n_estimators=100,
cv=5,
n_jobs=None,
n_init=10,
n_iter=190,
abs_tol=1e-3,
seed=123,
)
print(res3)
Loading

0 comments on commit 7bb241c

Please sign in to comment.