-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cross val. and lazy cross val. Pt.3
- Loading branch information
1 parent
8b4b796
commit 7bb241c
Showing
3 changed files
with
483 additions
and
0 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
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) |
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,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) |
Oops, something went wrong.