Competition Link:https://www.kaggle.com/c/house-prices-advanced-regression-techniques
# Libraries
!pip install scikit-optimize
!pip install optuna
import optuna
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statistics as st
import seaborn as sns
from matplotlib import pyplot
from sklearn.metrics import mean_squared_error
from time import time
Collecting scikit-optimize
Downloading scikit_optimize-0.9.0-py2.py3-none-any.whl (100 kB)
|████████████████████████████████| 100 kB 5.0 MB/s ta 0:00:011
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-optimize) (1.1.0)
Collecting pyaml>=16.9
Downloading pyaml-21.10.1-py2.py3-none-any.whl (24 kB)
Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.7/dist-packages (from scikit-optimize) (1.0.1)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.7/dist-packages (from scikit-optimize) (1.19.5)
Requirement already satisfied: scipy>=0.19.1 in /usr/local/lib/python3.7/dist-packages (from scikit-optimize) (1.4.1)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from pyaml>=16.9->scikit-optimize) (3.13)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.20.0->scikit-optimize) (3.0.0)
Installing collected packages: pyaml, scikit-optimize
Successfully installed pyaml-21.10.1 scikit-optimize-0.9.0
Collecting optuna
Downloading optuna-2.10.0-py3-none-any.whl (308 kB)
|████████████████████████████████| 308 kB 7.6 MB/s
Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from optuna) (3.13)
Collecting alembic
Downloading alembic-1.7.5-py3-none-any.whl (209 kB)
|████████████████████████████████| 209 kB 51.5 MB/s
Collecting colorlog
Downloading colorlog-6.6.0-py2.py3-none-any.whl (11 kB)
Collecting cliff
Downloading cliff-3.10.0-py3-none-any.whl (80 kB)
|████████████████████████████████| 80 kB 8.0 MB/s
Requirement already satisfied: scipy!=1.4.0 in /usr/local/lib/python3.7/dist-packages (from optuna) (1.4.1)
Collecting cmaes>=0.8.2
Downloading cmaes-0.8.2-py3-none-any.whl (15 kB)
Requirement already satisfied: sqlalchemy>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from optuna) (1.4.27)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from optuna) (1.19.5)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.7/dist-packages (from optuna) (21.3)
Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from optuna) (4.62.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging>=20.0->optuna) (3.0.6)
Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.7/dist-packages (from sqlalchemy>=1.1.0->optuna) (1.1.2)
Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from sqlalchemy>=1.1.0->optuna) (4.8.2)
Requirement already satisfied: importlib-resources in /usr/local/lib/python3.7/dist-packages (from alembic->optuna) (5.4.0)
Collecting Mako
Downloading Mako-1.1.6-py2.py3-none-any.whl (75 kB)
|████████████████████████████████| 75 kB 4.0 MB/s
Collecting stevedore>=2.0.1
Downloading stevedore-3.5.0-py3-none-any.whl (49 kB)
|████████████████████████████████| 49 kB 5.9 MB/s
Collecting cmd2>=1.0.0
Downloading cmd2-2.3.3-py3-none-any.whl (149 kB)
|████████████████████████████████| 149 kB 49.1 MB/s
Collecting autopage>=0.4.0
Downloading autopage-0.4.0-py3-none-any.whl (20 kB)
Collecting pbr!=2.1.0,>=2.0.0
Downloading pbr-5.8.0-py2.py3-none-any.whl (112 kB)
|████████████████████████████████| 112 kB 51.2 MB/s
Requirement already satisfied: PrettyTable>=0.7.2 in /usr/local/lib/python3.7/dist-packages (from cliff->optuna) (2.4.0)
Requirement already satisfied: attrs>=16.3.0 in /usr/local/lib/python3.7/dist-packages (from cmd2>=1.0.0->cliff->optuna) (21.2.0)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from cmd2>=1.0.0->cliff->optuna) (3.10.0.2)
Requirement already satisfied: wcwidth>=0.1.7 in /usr/local/lib/python3.7/dist-packages (from cmd2>=1.0.0->cliff->optuna) (0.2.5)
Collecting pyperclip>=1.6
Downloading pyperclip-1.8.2.tar.gz (20 kB)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->sqlalchemy>=1.1.0->optuna) (3.6.0)
Requirement already satisfied: MarkupSafe>=0.9.2 in /usr/local/lib/python3.7/dist-packages (from Mako->alembic->optuna) (2.0.1)
Building wheels for collected packages: pyperclip
Building wheel for pyperclip (setup.py) ... done
Created wheel for pyperclip: filename=pyperclip-1.8.2-py3-none-any.whl size=11136 sha256=13058c01b283540ca24540bff7af56bdf99f6d713e3f39caec2299583eb0efa6
Stored in directory: /root/.cache/pip/wheels/9f/18/84/8f69f8b08169c7bae2dde6bd7daf0c19fca8c8e500ee620a28
Successfully built pyperclip
Installing collected packages: pyperclip, pbr, stevedore, Mako, cmd2, autopage, colorlog, cmaes, cliff, alembic, optuna
Successfully installed Mako-1.1.6 alembic-1.7.5 autopage-0.4.0 cliff-3.10.0 cmaes-0.8.2 cmd2-2.3.3 colorlog-6.6.0 optuna-2.10.0 pbr-5.8.0 pyperclip-1.8.2 stevedore-3.5.0
data = pd.read_csv("kaggleCompetition.csv")
data
| MSSubClass | MSZoning | LotFrontage | LotArea | Street | Alley | LotShape | LandContour | Utilities | LotConfig | LandSlope | Neighborhood | Condition1 | Condition2 | BldgType | HouseStyle | OverallQual | OverallCond | YearBuilt | YearRemodAdd | RoofStyle | RoofMatl | Exterior1st | Exterior2nd | MasVnrType | MasVnrArea | ExterQual | ExterCond | Foundation | BsmtQual | BsmtCond | BsmtExposure | BsmtFinType1 | BsmtFinSF1 | BsmtFinType2 | BsmtFinSF2 | BsmtUnfSF | TotalBsmtSF | Heating | HeatingQC | CentralAir | Electrical | X1stFlrSF | X2ndFlrSF | LowQualFinSF | GrLivArea | BsmtFullBath | BsmtHalfBath | FullBath | HalfBath | BedroomAbvGr | KitchenAbvGr | KitchenQual | TotRmsAbvGrd | Functional | Fireplaces | FireplaceQu | GarageType | GarageYrBlt | GarageFinish | GarageCars | GarageArea | GarageQual | GarageCond | PavedDrive | WoodDeckSF | OpenPorchSF | EnclosedPorch | X3SsnPorch | ScreenPorch | PoolArea | PoolQC | Fence | MiscFeature | MiscVal | MoSold | YrSold | SaleType | SaleCondition | SalePrice | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 60 | 4 | 65.0 | 8450 | 2 | 1 | 4 | 4 | 1 | 5 | 1 | 6 | 3 | 3 | 1 | 6 | 7 | 5 | 2003 | 2003 | 2 | 2 | 13 | 14 | 2 | 196.0 | 3 | 5 | 3 | 3 | 4 | 4 | 3 | 706.0 | 6 | 0.0 | 150.0 | 856.0 | 2 | 1 | 2 | 5 | 856 | 854 | 0 | 1710 | 1.0 | 0.0 | 2 | 1 | 3 | 1 | 3 | 8 | 7 | 0 | 3 | 2 | 2003.000000 | 2 | 2.0 | 548.0 | 5 | 5 | 3 | 0 | 61 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 2 | 2008 | 9 | 5 | 12.247694 |
| 1 | 20 | 4 | 80.0 | 9600 | 2 | 1 | 4 | 4 | 1 | 3 | 1 | 25 | 2 | 3 | 1 | 3 | 6 | 8 | 1976 | 1976 | 2 | 2 | 9 | 9 | 3 | 0.0 | 4 | 5 | 2 | 3 | 4 | 2 | 1 | 978.0 | 6 | 0.0 | 284.0 | 1262.0 | 2 | 1 | 2 | 5 | 1262 | 0 | 0 | 1262 | 0.0 | 1.0 | 2 | 0 | 3 | 1 | 4 | 6 | 7 | 1 | 5 | 2 | 1976.000000 | 2 | 2.0 | 460.0 | 5 | 5 | 3 | 298 | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 5 | 2007 | 9 | 5 | 12.109011 |
| 2 | 60 | 4 | 68.0 | 11250 | 2 | 1 | 1 | 4 | 1 | 5 | 1 | 6 | 3 | 3 | 1 | 6 | 7 | 5 | 2001 | 2002 | 2 | 2 | 13 | 14 | 2 | 162.0 | 3 | 5 | 3 | 3 | 4 | 3 | 3 | 486.0 | 6 | 0.0 | 434.0 | 920.0 | 2 | 1 | 2 | 5 | 920 | 866 | 0 | 1786 | 1.0 | 0.0 | 2 | 1 | 3 | 1 | 3 | 6 | 7 | 1 | 5 | 2 | 2001.000000 | 2 | 2.0 | 608.0 | 5 | 5 | 3 | 0 | 42 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 9 | 2008 | 9 | 5 | 12.317167 |
| 3 | 70 | 4 | 60.0 | 9550 | 2 | 1 | 1 | 4 | 1 | 1 | 1 | 7 | 3 | 3 | 1 | 6 | 7 | 5 | 1915 | 1970 | 2 | 2 | 14 | 16 | 3 | 0.0 | 4 | 5 | 1 | 4 | 2 | 4 | 1 | 216.0 | 6 | 0.0 | 540.0 | 756.0 | 2 | 3 | 2 | 5 | 961 | 756 | 0 | 1717 | 1.0 | 0.0 | 1 | 0 | 3 | 1 | 3 | 7 | 7 | 1 | 3 | 6 | 1998.000000 | 3 | 3.0 | 642.0 | 5 | 5 | 3 | 0 | 35 | 272 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 2 | 2006 | 9 | 1 | 11.849398 |
| 4 | 60 | 4 | 84.0 | 14260 | 2 | 1 | 1 | 4 | 1 | 3 | 1 | 14 | 3 | 3 | 1 | 6 | 8 | 5 | 2000 | 2000 | 2 | 2 | 13 | 14 | 2 | 350.0 | 3 | 5 | 3 | 3 | 4 | 1 | 3 | 655.0 | 6 | 0.0 | 490.0 | 1145.0 | 2 | 1 | 2 | 5 | 1145 | 1053 | 0 | 2198 | 1.0 | 0.0 | 2 | 1 | 4 | 1 | 3 | 9 | 7 | 1 | 5 | 2 | 2000.000000 | 2 | 3.0 | 836.0 | 5 | 5 | 3 | 192 | 84 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 12 | 2008 | 9 | 5 | 12.429216 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2914 | 160 | 5 | 21.0 | 1936 | 2 | 1 | 4 | 4 | 1 | 5 | 1 | 11 | 3 | 3 | 4 | 6 | 4 | 7 | 1970 | 1970 | 2 | 2 | 6 | 6 | 3 | 0.0 | 4 | 5 | 2 | 4 | 4 | 4 | 6 | 0.0 | 6 | 0.0 | 546.0 | 546.0 | 2 | 3 | 2 | 5 | 546 | 546 | 0 | 1092 | 0.0 | 0.0 | 1 | 1 | 3 | 1 | 4 | 5 | 7 | 0 | 3 | 2 | 1978.113406 | 3 | 0.0 | 0.0 | 5 | 5 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 6 | 2006 | 9 | 5 | NaN |
| 2915 | 160 | 5 | 21.0 | 1894 | 2 | 1 | 4 | 4 | 1 | 5 | 1 | 11 | 3 | 3 | 5 | 6 | 4 | 5 | 1970 | 1970 | 2 | 2 | 6 | 6 | 3 | 0.0 | 4 | 5 | 2 | 4 | 4 | 4 | 5 | 252.0 | 6 | 0.0 | 294.0 | 546.0 | 2 | 5 | 2 | 5 | 546 | 546 | 0 | 1092 | 0.0 | 0.0 | 1 | 1 | 3 | 1 | 4 | 6 | 7 | 0 | 3 | 5 | 1970.000000 | 3 | 1.0 | 286.0 | 5 | 5 | 3 | 0 | 24 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 4 | 2006 | 9 | 1 | NaN |
| 2916 | 20 | 4 | 160.0 | 20000 | 2 | 1 | 4 | 4 | 1 | 5 | 1 | 12 | 3 | 3 | 1 | 3 | 5 | 7 | 1960 | 1996 | 2 | 2 | 13 | 14 | 3 | 0.0 | 4 | 5 | 2 | 4 | 4 | 4 | 1 | 1224.0 | 6 | 0.0 | 0.0 | 1224.0 | 2 | 1 | 2 | 5 | 1224 | 0 | 0 | 1224 | 1.0 | 0.0 | 1 | 0 | 4 | 1 | 4 | 7 | 7 | 1 | 5 | 6 | 1960.000000 | 3 | 2.0 | 576.0 | 5 | 5 | 3 | 474 | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 9 | 2006 | 9 | 1 | NaN |
| 2917 | 85 | 4 | 62.0 | 10441 | 2 | 1 | 4 | 4 | 1 | 5 | 1 | 12 | 3 | 3 | 1 | 7 | 5 | 5 | 1992 | 1992 | 2 | 2 | 7 | 16 | 3 | 0.0 | 4 | 5 | 3 | 3 | 4 | 1 | 3 | 337.0 | 6 | 0.0 | 575.0 | 912.0 | 2 | 5 | 2 | 5 | 970 | 0 | 0 | 970 | 0.0 | 1.0 | 1 | 0 | 3 | 1 | 4 | 6 | 7 | 0 | 3 | 2 | 1978.113406 | 3 | 0.0 | 0.0 | 5 | 5 | 3 | 80 | 32 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 700 | 7 | 2006 | 9 | 5 | NaN |
| 2918 | 60 | 4 | 74.0 | 9627 | 2 | 1 | 4 | 4 | 1 | 5 | 2 | 12 | 3 | 3 | 1 | 6 | 7 | 5 | 1993 | 1994 | 2 | 2 | 7 | 7 | 2 | 94.0 | 4 | 5 | 3 | 3 | 4 | 1 | 4 | 758.0 | 6 | 0.0 | 238.0 | 996.0 | 2 | 1 | 2 | 5 | 996 | 1004 | 0 | 2000 | 0.0 | 0.0 | 2 | 1 | 3 | 1 | 4 | 9 | 7 | 1 | 5 | 2 | 1993.000000 | 1 | 3.0 | 650.0 | 5 | 5 | 3 | 190 | 48 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 0 | 11 | 2006 | 9 | 5 | NaN |
2919 rows × 80 columns
data2 = data.values
## (X,y) contains the available data for model training, hyper-parameter tuning, model selection, and model evaluation
X = data2[0:1460,:-1]
y = data2[0:1460,-1]
## Competition data (will be used after training)
X_comp = data2[1460:,:-1]
y_comp = data2[1460:,-1] ## there is no data for now on
X.shape,y.shape, X_comp.shape, y_comp.shape
((1460, 79), (1460,), (1459, 79), (1459,))
from sklearn.model_selection import train_test_split
rn = np.random.seed(100459259)
x_train, x_test, y_train, y_test = train_test_split(X,y,
test_size=1/3,
random_state=rn)
print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)
(973, 79) (973,) (487, 79) (487,)
In this section we will implement several machine learning algorithms that allow us to create a model able to predict de houses' prices in the Boston dataset. In this section we will attach first to the default hyper-parameter values and then, we will perform hyper-parameter tuning in order to improve the performance of the models.
The visualization of the learning curves is very important to do model selection. If the model is overfitting, the learning curve will present a gap between the training and validation scores. In this case, the complexity of the model should be reduced. Moreover, if the model is underfitting, the learning curves will converge to a low score value. In this case, hyper-parameters tuning could improve such model. \ We will plot the learning curves from each model in order to detect any of the above-mentioned situations.
# Plot learning curves
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None,
n_jobs=1, train_sizes=np.linspace(.1, 1.0, 10)):
plt.figure()
plt.title(title)
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Training examples")
plt.ylabel("R2 Score")
train_sizes, train_scores, test_scores = learning_curve(
estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()
plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
train_scores_mean + train_scores_std, alpha=0.1,
color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
label="Training score")
plt.plot(train_sizes, test_scores_mean, 'o-', color="g",
label="Validation score")
plt.legend(loc="best")
return plt
We will implement 3-fold cross-validation in order to estimate the performance of the model. The Root Mean Squared Error (RMSE) will be computed for each fold of the cross-validation, and the estimated performance will be the mean of the three results.
# k-fold cross validation iterator of k=3 folds
from sklearn.model_selection import cross_val_score, KFold
## setting a seed to get reproducible results
rn=np.random.seed(100459259)
cv = KFold(n_splits=3, shuffle=True, random_state=rn)
from sklearn.neighbors import KNeighborsRegressor
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import learning_curve
from time import time
start = time()
pipe = Pipeline(steps=[('Standarization', StandardScaler()),
('Regressor', KNeighborsRegressor())])
knn_scores = -cross_val_score(pipe, x_train, y_train, cv=cv, scoring='neg_root_mean_squared_error')
end = time()
print("Scores: {}".format(knn_scores))
print("Mean of Scores: {}".format(knn_scores.mean()))
print("Standard Deviation of Scores: {}".format(knn_scores.std()))
print("Execution time:", end-start, "s")
title = "Learning Curves (KNN)"
plot_learning_curve(pipe, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
Scores: [0.20598134 0.18860906 0.19608956] Mean of Scores: 0.1968933178603667 Standard Deviation of Scores: 0.007114936805820695 Execution time: 0.04807114601135254 s
The RMSE of this model is approximately 0.20. As we can see from the learning curves plot, there is no overfitting, neither underfitting, although the performance could be improved.
from sklearn import tree
np.random.seed(100459259)
start = time()
dec_tree = tree.DecisionTreeRegressor()
dec_scores = -cross_val_score(dec_tree,
x_train, y_train,
scoring='neg_root_mean_squared_error',
cv = cv)
end = time()
print("Scores: {}".format(dec_scores))
print("Mean of Scores: {}".format(dec_scores.mean()))
print("Standard Deviation of Scores: {}".format(dec_scores.std()))
print("Execution time:", end-start, "s")
title = "Learning Curves (Decision Trees)"
plot_learning_curve(dec_tree, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
Scores: [0.21754682 0.22803065 0.2390408 ] Mean of Scores: 0.2282060904052544 Standard Deviation of Scores: 0.0087757604884593 Execution time: 0.05582404136657715 s
The RMSE is even larger than in the previous model. Moreover, the learning curves reveal that this model is overfitting, as the model fits perfectly the training data, while achieving very little performance when validating new data.
from sklearn.ensemble import ExtraTreesRegressor
np.random.seed(100459259)
start = time()
ext_tree = ExtraTreesRegressor()
ext_scores = -cross_val_score(ext_tree, x_train, y_train, cv=cv, scoring='neg_root_mean_squared_error')
end = time()
print("Scores: {}".format(ext_scores))
print("Mean of Scores: {}".format(ext_scores.mean()))
print("Standard deviation of the Scores: {}".format(ext_scores.std()))
print("Execution time:", end-start, "s")
title = "Learning Curves (Extra Trees)"
plot_learning_curve(ext_tree, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
Scores: [0.16068368 0.15240514 0.15042954] Mean of Scores: 0.15450611909135742 Standard deviation of the Scores: 0.004442032501198062 Execution time: 2.5495197772979736 s
The extra trees gives clearly better results than the simple tree regressor. In this case the RMSE is reduced and there is no overfitting.
from sklearn.ensemble import RandomForestRegressor
np.random.seed(100459259)
start = time()
rf_reg = RandomForestRegressor()
rf_scores = -cross_val_score(rf_reg, x_train, y_train, cv=cv, scoring='neg_root_mean_squared_error')
end = time()
print("Scores: {}".format(rf_scores))
print("Mean of Scores: {}".format(rf_scores.mean()))
print("Standard deviation of the Scores: {}".format(rf_scores.std()))
print("Execution time:", end-start, "s")
title = "Learning Curves (RF)"
plot_learning_curve(rf_reg, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
Scores: [0.14739849 0.16385016 0.15525203] Mean of Scores: 0.15550022541059716 Standard deviation of the Scores: 0.006718659754763993 Execution time: 3.075514078140259 s
Although the performance of this model is very similar to the previous one, extra trees gives still better results.
from sklearn.ensemble import HistGradientBoostingRegressor
np.random.seed(100459259)
start = time()
gb_reg = HistGradientBoostingRegressor()
gb_scores = -cross_val_score(gb_reg, x_train, y_train, cv=cv,scoring='neg_root_mean_squared_error')
end = time()
print("Scores: {}".format(gb_scores))
print("Mean of Scores: {}".format(gb_scores.mean()))
print("Standard deviation of the Scores: {}".format(gb_scores.std()))
print("Execution time:", end-start, "s")
title = "Learning Curves (GBM)"
plot_learning_curve(gb_reg, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
Scores: [0.14700189 0.16370471 0.14770372] Mean of Scores: 0.15280344148989017 Standard deviation of the Scores: 0.007713680932535797 Execution time: 2.1319127082824707 s
So far, this is the method that gives the best model. \
The performace of the five implemented methods are gathered in the following table:
| Method | RMSE | Exec. time (s) |
|---|---|---|
| KNN Regressor | 0.1968 | 0.0480 |
| Decision Tree Regressor | 0.2282 | 0.0558 |
| Random Tree Regressor | 0.1555 | 3.0755 |
| Extra Tree Regressor | 0.1545 | 2.5495 |
| HistGradient Regressor | 0.1528 | 2.1319 |
In this section we will try to improve the performance of the model given by KNN. I order to do so, we implement GridSearchCV. This function finds the hyper-parameter value (among the ones that are proposed) that minimizes the RMSE. This is done by 3-fold cross-validation on the training partition.
from sklearn.model_selection import GridSearchCV
np.random.seed(100459259)
start = time()
param_grid = [{'Regressor__n_neighbors': range(1,30,1)}]
gs_knn = GridSearchCV(pipe,
param_grid = param_grid,
scoring = 'neg_root_mean_squared_error',
cv=cv,
n_jobs = -1)
grid_search_knn = gs_knn.fit(x_train, y_train)
end = time()
gs_best_model = -grid_search_knn.best_score_
gs_best_k = grid_search_knn.best_params_
gs_ex_time = end-start
print("Best model: {}".format(gs_best_model))
print("Best k: {}".format(gs_best_k))
print("Execution time:", gs_ex_time, "s")
Best model: 0.19193289596100704
Best k: {'Regressor__n_neighbors': 8}
Execution time: 0.8218197822570801 s
The goal is to find the best maximum depth and the minimum samples split. Unlike, GridSearchCV, RandomizedSearchCV does not try the whole set of hyper-parameters. Instead, it chooses some values randomly and compares the performance of the resulted models.
from scipy.stats import uniform, expon
from scipy.stats import randint as sp_randint
from sklearn.model_selection import RandomizedSearchCV
np.random.seed(100459259)
start = time()
param_distributions = [{'max_depth': sp_randint(1,50),
'min_samples_split': sp_randint(1,50)}]
budget = 20
rs_dec_tree = RandomizedSearchCV(dec_tree,
param_distributions = param_distributions,
scoring = 'neg_root_mean_squared_error',
n_iter = budget,
cv=cv,
n_jobs = -1)
random_search_dec_tree = rs_dec_tree.fit(x_train, y_train)
end = time()
rs_best_model = -random_search_dec_tree.best_score_
rs_best_parameters = random_search_dec_tree.best_params_
rs_ex_time = end - start
print("Best model: {}".format(rs_best_model))
print("Best Parameters: {}".format(rs_best_parameters))
print("Execution time:", rs_ex_time, "s")
Best model: 0.1996881213178419
Best Parameters: {'max_depth': 11, 'min_samples_split': 17}
Execution time: 0.5258646011352539 s
To tune the hyper-parameters of Extra trees (again maximum depth and minimum samples split) we implement a Bayes Search. As before, not all the candidate values are tested, but in this case they are not chosen randomly either. Bayes SearchCV seeks the hyper-parameters that are more likely to improve the performance, ignoring the values that it considers are not worthy to try.
from skopt import BayesSearchCV
from skopt.space import Integer
np.random.seed(100459259)
start = time()
param_grid = {'max_depth': Integer(2, 20),
'min_samples_split': Integer(2, 20)}
budget = 20
bs_ext_tree = BayesSearchCV(ext_tree,
param_grid,
scoring = 'neg_root_mean_squared_error',
cv = cv,
n_jobs = -1, verbose = 1,
n_iter = budget)
bayes_search_ext_tree = bs_ext_tree.fit(x_train, y_train)
end = time()
best_model = -bayes_search_ext_tree.best_score_
best_parameters = bayes_search_ext_tree.best_params_
print("Best model: {}".format(best_model))
print("Best Parameters: {}".format(best_parameters))
print("Execution time:", end-start, "s")
Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits
/usr/local/lib/python3.7/dist-packages/skopt/optimizer/optimizer.py:449: UserWarning: The objective has been evaluated at this point before.
Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits Fitting 3 folds for each of 1 candidates, totalling 3 fits
/usr/local/lib/python3.7/dist-packages/skopt/optimizer/optimizer.py:449: UserWarning: The objective has been evaluated at this point before.
Fitting 3 folds for each of 1 candidates, totalling 3 fits
Best model: 0.1461576115910371
Best Parameters: OrderedDict([('max_depth', 12), ('min_samples_split', 2)])
Execution time: 36.50195264816284 s
In this section we will use the Optuna package. Optuna also implements by default a Bayes search to do hyper-parameter tuning. However, the coding is different from what we have seen so far. It is necessary to define the objective function, that is, the function we want to optimize. In each iteration, this function is called and evaluated with the new set of suggested hyper-parameters.
def objective(trial):
max_depth = trial.suggest_int('max_depth', 2, 16)
learning_rate = trial.suggest_uniform('learning_rate', 0, 1)
max_iter = trial.suggest_int('max_iter',10,600)
clf = HistGradientBoostingRegressor(max_depth = max_depth,
learning_rate = learning_rate,
max_iter = max_iter)
scores = -cross_val_score(clf, x_train, y_train,
scoring = 'neg_root_mean_squared_error',
n_jobs = -1, cv = cv)
inner_rmse = scores.mean()
return inner_rmse
np.random.seed(100459259)
start = time()
budget = 20
study = optuna.create_study(direction = 'minimize')
study.optimize(objective, n_trials = budget)
end = time()
best_model = study.best_value
best_parameters = study.best_params
print("Best model: {}".format(best_model))
print("Best Parameters: {}".format(best_parameters))
print("Execution time:", end-start, "s")
[I 2022-01-08 08:01:11,311] A new study created in memory with name: no-name-29a35334-3328-4008-baf4-338600eba163 [I 2022-01-08 08:01:12,308] Trial 0 finished with value: 0.2130934385884118 and parameters: {'max_depth': 6, 'learning_rate': 0.9067128139642723, 'max_iter': 100}. Best is trial 0 with value: 0.2130934385884118. [I 2022-01-08 08:01:17,988] Trial 1 finished with value: 0.14738162558938037 and parameters: {'max_depth': 10, 'learning_rate': 0.052384217812351586, 'max_iter': 483}. Best is trial 1 with value: 0.14738162558938037. [I 2022-01-08 08:01:22,050] Trial 2 finished with value: 0.15140620250310463 and parameters: {'max_depth': 5, 'learning_rate': 0.208711267045269, 'max_iter': 595}. Best is trial 1 with value: 0.14738162558938037. [I 2022-01-08 08:01:22,314] Trial 3 finished with value: 0.18690940799520198 and parameters: {'max_depth': 7, 'learning_rate': 0.767926511620015, 'max_iter': 20}. Best is trial 1 with value: 0.14738162558938037. [I 2022-01-08 08:01:29,192] Trial 4 finished with value: 0.1449794117894521 and parameters: {'max_depth': 11, 'learning_rate': 0.04021525744620269, 'max_iter': 532}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:35,977] Trial 5 finished with value: 0.15995132065442352 and parameters: {'max_depth': 12, 'learning_rate': 0.4248215046777173, 'max_iter': 491}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:39,958] Trial 6 finished with value: 0.193350525216761 and parameters: {'max_depth': 6, 'learning_rate': 0.8425079166800017, 'max_iter': 446}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:43,159] Trial 7 finished with value: 0.1804274289588236 and parameters: {'max_depth': 4, 'learning_rate': 0.7256873764878279, 'max_iter': 574}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:47,027] Trial 8 finished with value: 0.16365782306767004 and parameters: {'max_depth': 9, 'learning_rate': 0.3221540112910206, 'max_iter': 357}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:51,422] Trial 9 finished with value: 0.167816242099884 and parameters: {'max_depth': 8, 'learning_rate': 0.5836896557871962, 'max_iter': 400}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:55,255] Trial 10 finished with value: 0.16603897724714395 and parameters: {'max_depth': 16, 'learning_rate': 0.008625999476686873, 'max_iter': 234}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:01:59,283] Trial 11 finished with value: 0.14703315237030545 and parameters: {'max_depth': 13, 'learning_rate': 0.03506698012930965, 'max_iter': 266}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:03,205] Trial 12 finished with value: 0.15004610683942934 and parameters: {'max_depth': 13, 'learning_rate': 0.18842763755927133, 'max_iter': 268}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:06,176] Trial 13 finished with value: 0.14729134420317122 and parameters: {'max_depth': 14, 'learning_rate': 0.17047089003953436, 'max_iter': 184}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:10,515] Trial 14 finished with value: 0.15736690276179832 and parameters: {'max_depth': 11, 'learning_rate': 0.3764907684488534, 'max_iter': 324}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:11,005] Trial 15 finished with value: 0.16084491296185982 and parameters: {'max_depth': 2, 'learning_rate': 0.5434551327657765, 'max_iter': 166}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:17,296] Trial 16 finished with value: 0.14868934837436032 and parameters: {'max_depth': 15, 'learning_rate': 0.09284802137345438, 'max_iter': 395}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:21,263] Trial 17 finished with value: 0.15495582700544852 and parameters: {'max_depth': 12, 'learning_rate': 0.2364664574842258, 'max_iter': 287}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:24,577] Trial 18 finished with value: 0.3398170208963757 and parameters: {'max_depth': 10, 'learning_rate': 0.0010164255143760084, 'max_iter': 202}. Best is trial 4 with value: 0.1449794117894521. [I 2022-01-08 08:02:32,743] Trial 19 finished with value: 0.1598569589798921 and parameters: {'max_depth': 14, 'learning_rate': 0.29695384745562825, 'max_iter': 528}. Best is trial 4 with value: 0.1449794117894521.
Best model: 0.1449794117894521
Best Parameters: {'max_depth': 11, 'learning_rate': 0.04021525744620269, 'max_iter': 532}
Execution time: 81.43442630767822 s
Pruning algorithms allow terminating the learning process prematurely based on the result of previous trials. Pruning mechanism in general works in two phases: \ (1) It periodically monitors the intermediate objective values. \ (2) It terminates the trial that does not meet the predefined condition. \
In addition to the median stopping rule, which is the pruner that has been used below, Optuna also supports algorithms such as Successive Halving and Hyperband , but the basic ideas remain largely the same.
The median stopping rule is based on the following idea: \ If in a given step of the training process the value of the objective function (in this case, the mean squared error) is worse (larger) than the value that was returned by the same step of the previous trials, then the current trial is not worthy to complete and the training proccess is terminated. This way, unpromising trials are early detected and pruned, saving computational resources and time. More accurately, the condition to prune a trial is that the value of the objective function in a given step must be larger than the median of the values of the same step in the previous trials. \
In order to divide the training process in several steps, we need to implement the partial_fit function. This function does not train the model with the whole dataset at once, but adding incremental chunks of data instead. This is how we can detect unpromising trials and stop the training before all the chunks are added. However, the partial_fit function can just be implemented to some algorithms that can learn incrementally. This is the reason we have selected stochastic gradient descent regressor for this exercise. Hence, the hyper-parameter we need to optimize in this case is alpha. As our aim is to just to show how the pruning algorithm works, we will use reduced training and testing sets.\
We see that the code is very similar to the one in the above-mentioned section. Nevertheless, we find the following changes: \ 1) Inside the objective function we perform a loop of 20 iterations corresponding to the number of steps the training process is going to take. \ 2) Inside this loop we evaluate the model resulted from each step and we save the value of the error (score) of each step (trial.report). \ 3) The pruner is called at the end of each step to inspect whether the trial should be pruned or not. \ 4) The pruner is specified in the study session. \
In the output the pruned trials appear explicitly. \
from sklearn.linear_model import SGDRegressor
x_train_2 = x_train[0:300,:]
y_train_2 = y_train[0:300]
x_test_2 = x_train[300:400,:]
y_test_2 = y_train[300:400]
def objective_2(trial):
alpha = trial.suggest_float('alpha', 1e-5, 1e-1, log=True)
for step in range(20):
clf = SGDRegressor(alpha = alpha)
clf.partial_fit(x_train_2, y_train_2)
# Report intermediate objective value
intermediate_value = -clf.score(x_test_2, y_test_2)
trial.report(intermediate_value, step)
# Handle pruning based on the intermediate value.
if trial.should_prune():
raise optuna.TrialPruned()
return intermediate_value
budget = 20
np.random.seed(100459259)
study_2 = optuna.create_study(direction = 'minimize', pruner=optuna.pruners.MedianPruner())
study_2.optimize(objective_2, n_trials = budget)
[I 2022-01-08 08:03:27,751] A new study created in memory with name: no-name-0d27dfbb-9e70-440f-804a-bf878c4afe03 [I 2022-01-08 08:03:27,778] Trial 0 finished with value: 1.0711722743322264e+35 and parameters: {'alpha': 0.00011727604000216051}. Best is trial 0 with value: 1.0711722743322264e+35. [I 2022-01-08 08:03:27,802] Trial 1 finished with value: 5.201037287135799e+35 and parameters: {'alpha': 2.2442091658470777e-05}. Best is trial 0 with value: 1.0711722743322264e+35. [I 2022-01-08 08:03:27,827] Trial 2 finished with value: 2.5187724529259493e+35 and parameters: {'alpha': 0.009018866686404295}. Best is trial 0 with value: 1.0711722743322264e+35. [I 2022-01-08 08:03:27,851] Trial 3 finished with value: 1.5442516802836584e+35 and parameters: {'alpha': 0.0028967214901671596}. Best is trial 0 with value: 1.0711722743322264e+35. [I 2022-01-08 08:03:27,876] Trial 4 finished with value: 4.408281691981193e+34 and parameters: {'alpha': 0.0041757217075157095}. Best is trial 4 with value: 4.408281691981193e+34. [I 2022-01-08 08:03:27,882] Trial 5 pruned. [I 2022-01-08 08:03:27,887] Trial 6 pruned. [I 2022-01-08 08:03:27,893] Trial 7 pruned. [I 2022-01-08 08:03:27,925] Trial 8 finished with value: 1.7751285073989787e+34 and parameters: {'alpha': 0.061930944221623575}. Best is trial 8 with value: 1.7751285073989787e+34. [I 2022-01-08 08:03:27,954] Trial 9 finished with value: 6.791708780989554e+35 and parameters: {'alpha': 0.019520476352792866}. Best is trial 8 with value: 1.7751285073989787e+34. [I 2022-01-08 08:03:27,963] Trial 10 pruned. [I 2022-01-08 08:03:27,969] Trial 11 pruned. [I 2022-01-08 08:03:27,979] Trial 12 pruned. [I 2022-01-08 08:03:27,989] Trial 13 pruned. [I 2022-01-08 08:03:27,994] Trial 14 pruned. [I 2022-01-08 08:03:28,004] Trial 15 pruned. [I 2022-01-08 08:03:28,017] Trial 16 pruned. [I 2022-01-08 08:03:28,049] Trial 17 finished with value: 2.5322676997758953e+35 and parameters: {'alpha': 0.00015280843548636362}. Best is trial 8 with value: 1.7751285073989787e+34. [I 2022-01-08 08:03:28,092] Trial 18 finished with value: 3.790984352780305e+35 and parameters: {'alpha': 0.006948387474737001}. Best is trial 8 with value: 1.7751285073989787e+34. [I 2022-01-08 08:03:28,101] Trial 19 pruned.
Optuna offers a variety of graphical tools that help us visualize the optimization process. In this section we will discuss and implement some of them. For this purpose, the study session from section 3.1.4 will be used. Also, all the below-mentioned functions can use matplotlib as a backend.
In first place, we will use optuna.visualization.plot_optimization_history. Its output is a plot of the value of the objective function for each trial (blue dots). It also shows the current best value as a red line. This red line changes its position each time a new trial finds a better combination of hyperparameters. \
fig = optuna.visualization.plot_optimization_history(study)
fig.show()
Optuna also allows to study the importance of each parameter for the estimation of the objective function. Such importances can be visualized executing optuna.visualization.plot_param_importances.
fig = optuna.visualization.plot_param_importances(study)
fig.show()
From this plot we can conclude that the maximum depth is the least important hyper-parameter, while the learning rate is the most important one. This means that spending computational resources on searching the optimal learning rate would be much more efficient and would give similar results than searching for the whole optimal hyper-parameter space. \
Now we wil implement optuna.visualization.plot_slice. This function plots the value of the objective function againts the value of each hyper-parameter in each trial. This function allows to introduce a list of parameters to visualize, but by default all parameters are shown.
fig = optuna.visualization.plot_slice(study)
fig.show()
By using optuna.visualization.matplotlib.plot_parallel_coordinate it is possible to get a parallel coodinates plot (PCP). PCP draws coordinates in parallel axes and connects them with straight lines. The variables (hyper-parameters and objective function) are drawn into the horizontal axis and its values are mapped onto the vertical axis. Each line represents a trial.\ This graph helps to visualize if the election of any hyper-parameters is somehow skewed .
optuna.visualization.matplotlib.plot_parallel_coordinate(study)
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: ExperimentalWarning: plot_parallel_coordinate is experimental (supported from v2.2.0). The interface can change in the future.
<matplotlib.axes._subplots.AxesSubplot at 0x7f1e31d069d0>
Finally, we will make use of optuna.visualization.plot_contour. This command deploys parameter relationship as contour plot. The lighter areas show the values of the pair of hyper-parameter that minimizes the objective function.
fig = optuna.visualization.plot_contour(study)
fig.show()
Optuna allows to plot intermediate values of all trials in a study. Each step of the training process is drawn in the horizontal axis and the corresponding value of the objective function is mapped in the vertical axis. Every line represents a trial. \ To visualize it we will use the study session from section 3.1.5.
fig = optuna.visualization.plot_intermediate_values(study_2)
fig.show()
The results from hyper-parameter tuning are summed up in the following table:
| Method | Best hyper-parameters | New RMSE | Old RMSE | New exec. time (s) | Old exec.time (s) |
|---|---|---|---|---|---|
| KNN Regressor | Neighbours: 8 | 0.1919 | 0.1968 | 0.8218 | 0.0480 |
| Decision Tree Regressor | Max depth: 11, Min samples split: 17 | 0.1996 | 0.2282 | 0.5258 | 0.0558 |
| Extra tree Regressor | Max depth: 12, Min samples split: 2 | 0.1461 | 0.1545 | 36.5019 | 2.5495 |
| HistGradient Regressor | Max depth: 11, Learning rate: 0.04, Max iter: 532 | 0.1449 | 0.1528 | 81.4344 | 2.1319 |
As expected, the performance of all models has been improved. Also, we can see that the execution time increases with the complexity of the model. \ However, the use of the optimal hyper-parameter in KNN just improves the performance a 0.4% with respect to the previous model. Also, the time spent on the search plus model training takes 18 times more than the computation of the model trained with default hyper-parameters. So, the final result is a model that does not work much better and at cost of a longer execution time. Tuning hyper-parameters in this case is not beneficial. \ Hyper-parameter tuning in decision tree regressor achieves improvement with respect to the old model, but the algorithm takes 9 times longer. Also, the performance of this new model is still the worst among the studied models. \ On the other hand, Bayes search (implemented by both ways), gets a good improvement in the models given by extra tree regresor and histgradient regressor, respectively. The time taken in both cases is much longer than in the previous models, but now, by contrast, the extra time results in a great improvement of the model. \ Based on these results, the most efficient model is the one given by extra tree regressor, as its performance is almost identical to the histgradient regressor, but with the advantage of being a simpler model that takes a shorter time when doing hyper-parameter tuning. However, we will compare both methods in sections 3.1.8 and 3.2.
As an exercise, we will use optuna in order to perform hyper-parameter tunning, including also the model as a parameter of the search space.
def objective_cash(trial):
method = trial.suggest_categorical('method',['ext_tree','gb_reg'])
if (method == 'ext_tree'):
max_depth = trial.suggest_int('max_depth', 2, 20),
min_samples_split = trial.suggest_int('min_samples_split', 2, 20)
clf = ExtraTreesRegressor(max_depth = max_depth,
min_samples_split = min_samples_split)
else:
max_depth = trial.suggest_int('max_depth', 2, 16)
learning_rate = trial.suggest_uniform('learning_rate', 0, 1)
max_iter = trial.suggest_int('max_iter',10,600)
clf = HistGradientBoostingRegressor(max_depth = max_depth,
learning_rate = learning_rate,
max_iter = max_iter)
scores = -cross_val_score(clf, x_train, y_train,
scoring = 'neg_root_mean_squared_error',
n_jobs = -1, cv = cv)
inner_rmse = scores.mean()
return inner_rmse
np.random.seed(100459259)
budget = 40
study = optuna.create_study(direction = 'minimize')
study.optimize(objective_cash, n_trials = budget)
best_model = study.best_value
best_parameters = study.best_params
print("Best model: {}".format(best_model))
print("Best Parameters: {}".format(best_parameters))
[I 2022-01-08 08:18:23,346] A new study created in memory with name: no-name-2d89af53-0c59-4258-bfba-2916d3f8b3da [I 2022-01-08 08:18:24,640] Trial 0 finished with value: 0.18491840964220804 and parameters: {'method': 'gb_reg', 'max_depth': 11, 'learning_rate': 0.6908085895821249, 'max_iter': 22}. Best is trial 0 with value: 0.18491840964220804. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:24,776] Trial 1 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:24,923] Trial 2 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:25,055] Trial 3 failed, because the objective function returned nan. [I 2022-01-08 08:18:30,201] Trial 4 finished with value: 0.15705660891138118 and parameters: {'method': 'gb_reg', 'max_depth': 15, 'learning_rate': 0.32156070456269137, 'max_iter': 326}. Best is trial 4 with value: 0.15705660891138118. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:30,331] Trial 5 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:30,470] Trial 6 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:30,595] Trial 7 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:30,725] Trial 8 failed, because the objective function returned nan. [I 2022-01-08 08:18:31,896] Trial 9 finished with value: 0.2166639068654572 and parameters: {'method': 'gb_reg', 'max_depth': 10, 'learning_rate': 0.9258456308266979, 'max_iter': 80}. Best is trial 4 with value: 0.15705660891138118. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:32,017] Trial 10 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:32,152] Trial 11 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:32,273] Trial 12 failed, because the objective function returned nan. [I 2022-01-08 08:18:32,446] Trial 13 finished with value: 0.15110626517816028 and parameters: {'method': 'gb_reg', 'max_depth': 6, 'learning_rate': 0.2875939063870664, 'max_iter': 10}. Best is trial 13 with value: 0.15110626517816028. [I 2022-01-08 08:18:34,246] Trial 14 finished with value: 0.15295200339145695 and parameters: {'method': 'gb_reg', 'max_depth': 4, 'learning_rate': 0.3110254032109373, 'max_iter': 319}. Best is trial 13 with value: 0.15110626517816028. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:34,372] Trial 15 failed, because the objective function returned nan. [I 2022-01-08 08:18:37,009] Trial 16 finished with value: 0.1568664138302984 and parameters: {'method': 'gb_reg', 'max_depth': 4, 'learning_rate': 0.29750926401027145, 'max_iter': 488}. Best is trial 13 with value: 0.15110626517816028. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:37,130] Trial 17 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:37,261] Trial 18 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:37,385] Trial 19 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:37,502] Trial 20 failed, because the objective function returned nan. [I 2022-01-08 08:18:38,005] Trial 21 finished with value: 0.1354060906302897 and parameters: {'method': 'gb_reg', 'max_depth': 2, 'learning_rate': 0.09914427256278313, 'max_iter': 186}. Best is trial 21 with value: 0.1354060906302897. [I 2022-01-08 08:18:41,341] Trial 22 finished with value: 0.16807266053792866 and parameters: {'method': 'gb_reg', 'max_depth': 11, 'learning_rate': 0.5397136681369388, 'max_iter': 248}. Best is trial 21 with value: 0.1354060906302897. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:41,477] Trial 23 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:41,594] Trial 24 failed, because the objective function returned nan. [I 2022-01-08 08:18:48,836] Trial 25 finished with value: 0.20879374355559013 and parameters: {'method': 'gb_reg', 'max_depth': 15, 'learning_rate': 0.8769127013510241, 'max_iter': 448}. Best is trial 21 with value: 0.1354060906302897. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:48,957] Trial 26 failed, because the objective function returned nan. [I 2022-01-08 08:18:49,084] Trial 27 finished with value: 0.15905266784474079 and parameters: {'method': 'gb_reg', 'max_depth': 2, 'learning_rate': 0.48159209787180735, 'max_iter': 28}. Best is trial 21 with value: 0.1354060906302897. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,216] Trial 28 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,344] Trial 29 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,484] Trial 30 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,623] Trial 31 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,758] Trial 32 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:49,896] Trial 33 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,026] Trial 34 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,161] Trial 35 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,297] Trial 36 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,427] Trial 37 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,561] Trial 38 failed, because the objective function returned nan. /usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py:372: FitFailedWarning: 3 fits failed out of a total of 3. The score on these train-test partitions for these parameters will be set to nan. If these failures are not expected, you can try to debug them by setting error_score='raise'. Below are more details about the failures: -------------------------------------------------------------------------------- 3 fits failed with the following error: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/sklearn/model_selection/_validation.py", line 681, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 459, in fit for i, t in enumerate(trees) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 1043, in __call__ if self.dispatch_one_batch(iterator): File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 861, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 779, in _dispatch job = self._backend.apply_async(batch, callback=cb) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 208, in apply_async result = ImmediateResult(func) File "/usr/local/lib/python3.7/dist-packages/joblib/_parallel_backends.py", line 572, in __init__ self.results = batch() File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in __call__ for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/joblib/parallel.py", line 263, in <listcomp> for func, args, kwargs in self.items] File "/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py", line 211, in __call__ return self.function(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/sklearn/ensemble/_forest.py", line 187, in _parallel_build_trees tree.fit(X, y, sample_weight=sample_weight, check_input=False) File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 1320, in fit X_idx_sorted=X_idx_sorted, File "/usr/local/lib/python3.7/dist-packages/sklearn/tree/_classes.py", line 305, in fit if max_depth <= 0: TypeError: '<=' not supported between instances of 'tuple' and 'int' [W 2022-01-08 08:18:50,707] Trial 39 failed, because the objective function returned nan.
Best model: 0.1354060906302897
Best Parameters: {'method': 'gb_reg', 'max_depth': 2, 'learning_rate': 0.09914427256278313, 'max_iter': 186}
The model selected is histgradient regressor. This is not surprising, as we have seen before that the performance of this model is slightly better than the extra tree regressor. However, the selected hyper-parameters do not coincide with the ones we had previously found. Also, this new set results in a better performace.
The histgradient boosting regressor and extra trees performed quite well, therefore, we will evaluate these two models in test sample in order to see their performance in test dataset. The reason to evaluate these two well-performed models in test sample is to find out whether these models also perform good in test sample or not.
After comparing two methods in 3.1.8 histgradient has been chosen , therefore, we will use the hyper-parameters of CASH for histgradient boosting regressor and hyper-parameters given by Bayes search for extra trees. Afterwards, we will compare the results and choose the best model.
# Training with the training partition and evaluation with the test partition.
np.random.seed(100459259)
model_hgbm = HistGradientBoostingRegressor(max_depth = 2,
learning_rate = 0.09914427256278313,
max_iter = 186)
model_hgbm.fit(x_train, y_train)
pred_hgbm = model_hgbm.predict(x_test)
title = "Learning Curves (HGBM)"
cv = cv
plot_learning_curve(model_hgbm, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
# Evaluation of the model
mse = mean_squared_error(y_test, pred_hgbm)
rmse = np.sqrt(mse)
print('Root Mean Squared Error (RMSE): %.4f' % rmse)
import statsmodels.api as sm
model_gb_ols = sm.OLS(model_hgbm.predict(x_test), y_test)
print(model_gb_ols.fit().summary())
# Scatter Plot
lineStart = y_test.min()
lineEnd = model_hgbm.predict(x_test).max()
plt.style.use('seaborn')
plt.figure()
plt.scatter(y_test, pred_hgbm, color = 'k', alpha=0.5, linewidths=3, label='data')
plt.plot([lineStart, lineEnd], [lineStart, lineEnd], 'k-', color = 'r', label='reference line')
# plt.xlim(lineStart, lineEnd)
# plt.ylim(lineStart, lineEnd)
plt.title("Model Performance Graph-ETR (Test set)")
plt.xlabel("Sale Price")
plt.ylabel("Pred Sale Price")
plt.legend()
plt.show()
Root Mean Squared Error (RMSE): 0.1256
/usr/local/lib/python3.7/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
OLS Regression Results
=======================================================================================
Dep. Variable: y R-squared (uncentered): 1.000
Model: OLS Adj. R-squared (uncentered): 1.000
Method: Least Squares F-statistic: 4.470e+06
Date: Sat, 08 Jan 2022 Prob (F-statistic): 0.00
Time: 08:20:57 Log-Likelihood: 319.45
No. Observations: 487 AIC: -636.9
Df Residuals: 486 BIC: -632.7
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
x1 0.9997 0.000 2114.172 0.000 0.999 1.001
==============================================================================
Omnibus: 149.107 Durbin-Watson: 2.010
Prob(Omnibus): 0.000 Jarque-Bera (JB): 1942.981
Skew: 0.934 Prob(JB): 0.00
Kurtosis: 12.605 Cond. No. 1.00
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
# Training with the training partition and evaluation with the test partition.
np.random.seed(100459259)
model_extree =ExtraTreesRegressor(max_depth = 12,
min_samples_split = 2)
model_extree.fit(x_train, y_train)
pred_extree = model_extree.predict(x_test)
title = "Learning Curves (ETR)"
cv = cv
plot_learning_curve(model_extree, title,
x_train, y_train, ylim=(0, 1.5),
cv=cv, n_jobs=-1);
# Evaluation of the model
mse = mean_squared_error(y_test, pred_extree)
rmse = np.sqrt(mse)
print('Root Mean Squared Error (RMSE): %.4f' % rmse)
import statsmodels.api as sm
model_gb_ols = sm.OLS(model_extree.predict(x_test), y_test)
print(model_gb_ols.fit().summary())
# Scatter Plot
lineStart = y_test.min()
lineEnd = model_extree.predict(x_test).max()
plt.style.use('seaborn')
plt.figure()
plt.scatter(y_test, pred_hgbm, color = 'k', alpha=0.5, linewidths=3, label='data')
plt.plot([lineStart, lineEnd], [lineStart, lineEnd], 'k-', color = 'r', label='reference line')
# plt.xlim(lineStart, lineEnd)
# plt.ylim(lineStart, lineEnd)
plt.title("Model Performance Graph-ETR (Test set)")
plt.xlabel("Sale Price")
plt.ylabel("Pred Sale Price")
plt.legend()
plt.show()
Root Mean Squared Error (RMSE): 0.1453
OLS Regression Results
=======================================================================================
Dep. Variable: y R-squared (uncentered): 1.000
Model: OLS Adj. R-squared (uncentered): 1.000
Method: Least Squares F-statistic: 3.339e+06
Date: Sat, 08 Jan 2022 Prob (F-statistic): 0.00
Time: 08:21:27 Log-Likelihood: 248.23
No. Observations: 487 AIC: -494.5
Df Residuals: 486 BIC: -490.3
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
x1 1.0001 0.001 1827.277 0.000 0.999 1.001
==============================================================================
Omnibus: 152.506 Durbin-Watson: 1.968
Prob(Omnibus): 0.000 Jarque-Bera (JB): 1403.177
Skew: 1.079 Prob(JB): 2.01e-305
Kurtosis: 11.031 Cond. No. 1.00
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
To conclude, Hist Gradient Boosting model performed better than Extra Trees with very few difference. The test-rmse has been found 0.1256 for HGBM and 0.1453 for Extra Trees. This result makes clear that we should use Hist Gradient Boosting model to make the final model.
In this part, the sale price will be predicted for X_comp sample. Hist Gradient Boosting model will be used to predict.
# Training the model with the whole dataset.
model_hgbm.fit(X, y)
y_comp = model_hgbm.predict(X_comp)
# Transformation of log(price) to actual price.
SalePrice = np.exp(y_comp)
Id = list(range(1461,2920))
pred_df_hgbm = pd.DataFrame({"Id": Id, "SalePrice": SalePrice})
pred_df_hgbm
| Id | SalePrice | |
|---|---|---|
| 0 | 1461 | 109989.428271 |
| 1 | 1462 | 156560.414811 |
| 2 | 1463 | 180616.704672 |
| 3 | 1464 | 180830.693754 |
| 4 | 1465 | 193483.884263 |
| ... | ... | ... |
| 1454 | 2915 | 78350.262744 |
| 1455 | 2916 | 83577.498496 |
| 1456 | 2917 | 171925.379315 |
| 1457 | 2918 | 120925.954380 |
| 1458 | 2919 | 238361.851598 |
1459 rows × 2 columns
We save the final results in .csv.
from google.colab import drive
drive.mount('/drive')
Drive already mounted at /drive; to attempt to forcibly remount, call drive.mount("/drive", force_remount=True).
pred_df_hgbm.to_csv('/drive/My Drive/Predictions_HGBM.csv', index=False)
Halving Grid Search is an optimized version of Grid Search hyperparameter optimization. Halving Grid Search searches over a given list of hyperparameters using a sequential bisection approach. The search strategy begins evaluating all candidates on a small sample of data and iteratively selects the best candidates using increasingly larger numbers of samples. HalvingGridSearchCV, which is inside of the Scikit-Learn library, will be used to imply this method for KNN model.
Halving Randomized Search uses the same sequential halving approach and it is even more optimized than Grid Search. Unlike Halving Grid Search, it is not trained on all hyper-parameter combinations, but instead picks a random set of hyper-parameter combinations. HalvingRandomizedSeachCV, which is also inside of the Scikit-Learn library, will be used to imply this method for decision tree regressor model.
Parameters definition:
factor: the proportion of candidates that are selected for each subsequent iteration. For example, factor=3 means that only one third of the candidates are selected.
resource: 'n_samples' defines the resource that increases with each iteration. By default, the resource is the number of samples.
min_resources: The minimum amount of resource that any candidate is allowed to use for a given iteration.
Attributes definition:
nresources: The amount of resources used at each iteration.
ncandidates: The number of candidate parameters evaluated at each iteration.
niterations: The actual number of iterations that were run. This is equal to min(n_possibleiterations, n_requirediterations). Because we did not say n_iterations_int aggressive_elimination is True.
import time
from sklearn.experimental import enable_halving_search_cv
from sklearn.model_selection import HalvingGridSearchCV
from sklearn.model_selection import cross_val_score, KFold
rn = np.random.seed(100459259)
cv = KFold(n_splits=3, shuffle=False, random_state=rn)
FACTOR = 2
MAX_RESOURCE_DIVISOR = 4
n_samples = x_train.shape[0]
param_grid = [{'Regressor__n_neighbors': range(1,30,1)}]
start_time = time.time()
halving_grid_search_knn = HalvingGridSearchCV(pipe,resource='n_samples',
min_resources=n_samples//MAX_RESOURCE_DIVISOR,
factor=FACTOR,
param_grid = param_grid,
scoring = 'neg_root_mean_squared_error',
cv=cv, n_jobs = -1).fit(x_train, y_train)
end_time = time.time()
halving_best_model = -halving_grid_search_knn.best_score_
halving_best_k = halving_grid_search_knn.best_params_
resources = halving_grid_search_knn.n_resources_
iterations = halving_grid_search_knn.n_iterations_
candidates = halving_grid_search_knn.n_candidates_
hl_ex_time = end_time - start_time
print("Best CV Score: {}".format(halving_best_model))
print("Best k: {}".format(halving_best_k))
print("Resources: {}".format(resources))
print("Iterations: {}".format(iterations))
print("n_canditates: {}".format(candidates))
print("execution time: {}".format(round(hl_ex_time,4)))
results = pd.DataFrame(halving_grid_search_knn.cv_results_)
Best CV Score: 0.18710573758786322
Best k: {'Regressor__n_neighbors': 9}
Resources: [243, 486, 972]
Iterations: 3
n_canditates: [29, 15, 8]
execution time: 1.3717
results.head()
| iter | n_resources | mean_fit_time | std_fit_time | mean_score_time | std_score_time | param_Regressor__n_neighbors | params | split0_test_score | split1_test_score | split2_test_score | mean_test_score | std_test_score | rank_test_score | split0_train_score | split1_train_score | split2_train_score | mean_train_score | std_train_score | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 243 | 0.003168 | 0.001411 | 0.001755 | 0.000305 | 1 | {'Regressor__n_neighbors': 1} | -0.209411 | -0.246014 | -0.261846 | -0.239090 | 0.021959 | 45 | -0.000000 | -0.000000 | -0.000000 | 0.000000 | 0.000000 |
| 1 | 0 | 243 | 0.002686 | 0.000446 | 0.001710 | 0.000153 | 2 | {'Regressor__n_neighbors': 2} | -0.193596 | -0.212691 | -0.260143 | -0.222143 | 0.027978 | 33 | -0.113563 | -0.115403 | -0.143552 | -0.124173 | 0.013724 |
| 2 | 0 | 243 | 0.002107 | 0.000508 | 0.001845 | 0.000362 | 3 | {'Regressor__n_neighbors': 3} | -0.199602 | -0.200762 | -0.242313 | -0.214225 | 0.019866 | 23 | -0.127867 | -0.151207 | -0.172497 | -0.150524 | 0.018226 |
| 3 | 0 | 243 | 0.004077 | 0.002848 | 0.002095 | 0.000166 | 4 | {'Regressor__n_neighbors': 4} | -0.204452 | -0.194982 | -0.220181 | -0.206538 | 0.010393 | 9 | -0.137830 | -0.165328 | -0.180925 | -0.161361 | 0.017816 |
| 4 | 0 | 243 | 0.002030 | 0.000097 | 0.004152 | 0.002142 | 5 | {'Regressor__n_neighbors': 5} | -0.206853 | -0.210919 | -0.214288 | -0.210686 | 0.003040 | 12 | -0.141614 | -0.171847 | -0.193627 | -0.169029 | 0.021328 |
results["params_str"] = results.params.apply(str)
results.drop_duplicates(subset=("params_str", "iter"), inplace=True)
mean_scores = results.pivot(index="iter", columns="params_str", values="mean_test_score")
ax = mean_scores.plot(legend=False, alpha=0.6)
labels = [f"iter={i}\nn_samples={resources[i]}\nn_candidates={candidates[i]}"
for i in range(iterations)]
ax.set_xticks(range(iterations))
ax.set_xticklabels(labels, multialignment="left")
ax.set_title("Scores of candidates over iterations")
ax.set_ylabel("mean test score", fontsize=15)
ax.set_xlabel("iterations", fontsize=15)
plt.tight_layout()
plt.show()
The execution time is a little longer for HalvingGridSearchCV compared to GridSearchCV. Generally, HalvingGridSearchCV optimizes the execution time, however for KNN not many parameters have been tried. Maybe because of that, the execution times are quite similar.
On the other hand, HalvingGridSearchCV selects a different number of neighbours, but the RMSE is reduced compared to GridSearchCV. HalvingGridSearchCV has found better CV result than GridSearchCV.
Both CV results are shown below:
Grid = pd.DataFrame(gs_best_k, index=[0]).assign(RMSE=gs_best_model, Method="Grid Search" ,Execution_Time = gs_ex_time)
Halving = pd.DataFrame(halving_best_k, index=[0]).assign(RMSE=halving_best_model, Method="Halving Grid Search",Execution_Time=hl_ex_time)
Grid_Halving_Comparison = Grid.append(Halving, ignore_index=True)
Grid_Halving_Comparison.index = Grid_Halving_Comparison['Method']
Grid_Halving_Comparison.drop('Method', axis=1, inplace=True)
Grid_Halving_Comparison.index.name = ''
Grid_Halving_Comparison
| Regressor__n_neighbors | RMSE | Execution_Time | |
|---|---|---|---|
| Grid Search | 8 | 0.191933 | 0.821820 |
| Halving Grid Search | 9 | 0.187106 | 1.371696 |
from scipy.stats import uniform, expon
from scipy.stats import randint as sp_randint
from sklearn.experimental import enable_halving_search_cv
from sklearn.model_selection import HalvingRandomSearchCV
import time
param_distributions = [{'max_depth': sp_randint(1,50),
'min_samples_split': sp_randint(1,50)}]
FACTOR = 2
MAX_RESOURCE_DIVISOR = 4
n_samples = x_train.shape[0]
rn = np.random.seed(100459259)
start_time = time.time()
rs_dec_tree = HalvingRandomSearchCV(dec_tree,
resource='n_samples',
min_resources= n_samples//MAX_RESOURCE_DIVISOR,
factor = FACTOR,
param_distributions = param_distributions,
scoring = 'neg_root_mean_squared_error',
cv=3,
n_jobs = -1,
random_state = rn).fit(x_train, y_train)
end_time = time.time()
hl_rs_best_model = -rs_dec_tree.best_score_
hl_rs_best_parameters = rs_dec_tree.best_params_
hl_rs_resources = rs_dec_tree.n_resources_
hl_rs_iterations = rs_dec_tree.n_iterations_
hl_rs_candidates = rs_dec_tree.n_candidates_
hl_rs_ex_time = end_time - start_time
print("Best CV Score: {}".format(hl_rs_best_model))
print("Best k: {}".format(hl_rs_best_parameters))
print("Resources: {}".format(hl_rs_resources))
print("Iterations: {}".format(hl_rs_iterations))
print("n_canditates: {}".format(hl_rs_candidates))
print("execution time: {}".format(round(hl_rs_ex_time,4)))
hl_rs_results = pd.DataFrame(rs_dec_tree.cv_results_)
Best CV Score: 0.2174088629777469
Best k: {'max_depth': 31, 'min_samples_split': 32}
Resources: [243, 486, 972]
Iterations: 3
n_canditates: [4, 2, 1]
execution time: 0.1689
hl_rs_results
| iter | n_resources | mean_fit_time | std_fit_time | mean_score_time | std_score_time | param_max_depth | param_min_samples_split | params | split0_test_score | split1_test_score | split2_test_score | mean_test_score | std_test_score | rank_test_score | split0_train_score | split1_train_score | split2_train_score | mean_train_score | std_train_score | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 243 | 0.003419 | 0.000108 | 0.000887 | 0.000126 | 27 | 21 | {'max_depth': 27, 'min_samples_split': 21} | -0.251116 | -0.301962 | -0.295848 | -0.282975 | 0.022666 | 6 | -0.117589 | -0.139457 | -0.146530 | -0.134525 | 0.012319 |
| 1 | 0 | 243 | 0.003005 | 0.000516 | 0.002024 | 0.001833 | 7 | 27 | {'max_depth': 7, 'min_samples_split': 27} | -0.267964 | -0.304760 | -0.263099 | -0.278608 | 0.018599 | 5 | -0.142748 | -0.150692 | -0.192447 | -0.161962 | 0.021799 |
| 2 | 0 | 243 | 0.002597 | 0.000078 | 0.000696 | 0.000016 | 31 | 32 | {'max_depth': 31, 'min_samples_split': 32} | -0.271619 | -0.301626 | -0.259657 | -0.277634 | 0.017654 | 4 | -0.158552 | -0.166397 | -0.196453 | -0.173801 | 0.016335 |
| 3 | 0 | 243 | 0.002973 | 0.000587 | 0.000605 | 0.000201 | 7 | 14 | {'max_depth': 7, 'min_samples_split': 14} | -0.257489 | -0.301076 | -0.304719 | -0.287761 | 0.021457 | 7 | -0.103240 | -0.122244 | -0.138685 | -0.121390 | 0.014483 |
| 4 | 1 | 486 | 0.005545 | 0.000072 | 0.000844 | 0.000055 | 7 | 27 | {'max_depth': 7, 'min_samples_split': 27} | -0.234354 | -0.196066 | -0.198190 | -0.209537 | 0.017570 | 2 | -0.130952 | -0.126561 | -0.130924 | -0.129479 | 0.002063 |
| 5 | 1 | 486 | 0.006690 | 0.001349 | 0.000983 | 0.000242 | 31 | 32 | {'max_depth': 31, 'min_samples_split': 32} | -0.233772 | -0.193404 | -0.195873 | -0.207683 | 0.018475 | 1 | -0.134993 | -0.124898 | -0.157380 | -0.139090 | 0.013574 |
| 6 | 2 | 972 | 0.011117 | 0.001601 | 0.000918 | 0.000147 | 31 | 32 | {'max_depth': 31, 'min_samples_split': 32} | -0.220697 | -0.215651 | -0.215878 | -0.217409 | 0.002327 | 3 | -0.126795 | -0.129520 | -0.134566 | -0.130293 | 0.003219 |
Execution of HalvingRandomSearchCV compared to RandomSearchCV is faster as HalvingRandomSearchCV is an optimized method of random search.
With HalvingRandomSearchCV, different regressor n neighbors has been selected as best parameter and the RMSE went down compared to RandomSearchCV. HalvingRandomSearchCV has found better CV result than RandomSearchCV.
Both CV results are shown below:
RandomSearch = pd.DataFrame(rs_best_parameters, index=[0]).assign(RMSE=rs_best_model, Method="Random Search" ,Execution_Time = rs_ex_time)
Halving_RS = pd.DataFrame(hl_rs_best_parameters, index=[0]).assign(RMSE=hl_rs_best_model, Method="Halving Random Search",Execution_Time=hl_rs_ex_time)
RS_Halving_Comparison = RandomSearch.append(Halving_RS, ignore_index=True)
RS_Halving_Comparison.index = RS_Halving_Comparison['Method']
RS_Halving_Comparison.drop('Method', axis=1, inplace=True)
RS_Halving_Comparison.index.name = ''
RS_Halving_Comparison
| max_depth | min_samples_split | RMSE | Execution_Time | |
|---|---|---|---|---|
| Random Search | 11 | 17 | 0.199688 | 0.525865 |
| Halving Random Search | 31 | 32 | 0.217409 | 0.168911 |
hl_rs_results["params_str"] = hl_rs_results.params.apply(str)
hl_rs_results.drop_duplicates(subset=("params_str", "iter"), inplace=True)
mean_scores = hl_rs_results.pivot(index="iter", columns="params_str", values="mean_test_score")
ax = mean_scores.plot(legend=False, alpha=0.6)
labels = [f"iter={i}\nn_samples={hl_rs_resources[i]}\nn_candidates={hl_rs_candidates[i]}"
for i in range(hl_rs_iterations)]
ax.set_xticks(range(hl_rs_iterations))
ax.set_xticklabels(labels, multialignment="left")
ax.set_title("Scores of candidates over iterations")
ax.set_ylabel("mean test score", fontsize=15)
ax.set_xlabel("iterations", fontsize=15)
plt.tight_layout()
plt.show()
XGBoost is an optimized Gradient Boosting algorithm through parallel processing with threads, tree-pruning, handling missing values and regularization to avoid overfitting/bias.
Before using XGBModel, data is called again because in previous section, we have done the prediction and found y_comp. After calling the data again from the same excel file, all x_train, y_train, x_test and y_test transformed to sparse matrises.
import xgboost as xgb
data2 = data.values
## (X,y) contains the available data for model training, hyper-parameter tuning, model selection, and model evaluation
X = data2[0:1460,:-1]
y = data2[0:1460,-1]
## Competition data (will be used after training)
X_comp = data2[1460:,:-1]
y_comp = data2[1460:,-1] ## there is no data for now on
## splitting the data
from sklearn.model_selection import train_test_split
np.random.seed(100459259)
x_train, x_test, y_train, y_test = train_test_split(X,y,
test_size=1/3,
random_state=0)
## feature names
data_nontarget = data.iloc[:,0:79]
features = data_nontarget.columns
## creating sparse and dense matrises for XGBModel
import scipy
from scipy.sparse import csr_matrix
# full data
X_csr = csr_matrix(X)
dense_full = xgb.DMatrix(X_csr, label = y,feature_names=features)
sparse_train = scipy.sparse.csr_matrix(x_train)
label_train = y_train
dense_train = xgb.DMatrix(sparse_train, label=label_train,feature_names=features)
sparse_test = scipy.sparse.csr_matrix(x_test)
label_test = y_test
dense_test = xgb.DMatrix(sparse_test, label=label_test, feature_names=features)
## XGBModel estimator
from xgboost import XGBRegressor
estimator = XGBRegressor(objective= 'reg:squarederror',
nthread=4,
seed=100459259
)
def objective(trial):
max_depth = trial.suggest_int('max_depth', 2, 12)
learning_rate = trial.suggest_uniform('learning_rate', 0, 1)
gamma = trial.suggest_uniform('gamma', 0, 1)
n_estimators = trial.suggest_int('n_estimators',60,300)
estimator_optuna = XGBRegressor(objective = "reg:squarederror",
max_depth = max_depth,
learning_rate = learning_rate,
gamma = gamma,
n_estimators = n_estimators,
booster = 'dart',
seed=100459259)
scores = -cross_val_score(estimator, sparse_train,label_train,
scoring = 'neg_root_mean_squared_error',
n_jobs = -1, cv = cv)
inner_rmse = scores.mean()
return inner_rmse
np.random.seed(100459259)
budget = 20
study = optuna.create_study(direction = 'minimize')
study.optimize(objective, n_trials = budget)
best_model = study.best_value
best_parameters = study.best_params
print("Best model: {}".format(best_model))
print("Best Parameters: {}".format(best_parameters))
print("Execution time:", end-start, "s")
[I 2022-01-08 08:25:48,373] A new study created in memory with name: no-name-531b0d2e-6b16-4427-a8ce-c65799389d9e [I 2022-01-08 08:25:49,496] Trial 0 finished with value: 0.1362920035418675 and parameters: {'max_depth': 7, 'learning_rate': 0.7434376700388832, 'gamma': 0.3746205790870919, 'n_estimators': 233}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:50,145] Trial 1 finished with value: 0.1362920035418675 and parameters: {'max_depth': 8, 'learning_rate': 0.7371528679130374, 'gamma': 0.6621770070334536, 'n_estimators': 99}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:50,765] Trial 2 finished with value: 0.1362920035418675 and parameters: {'max_depth': 5, 'learning_rate': 0.7550214389901565, 'gamma': 0.03265835790944227, 'n_estimators': 163}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:51,425] Trial 3 finished with value: 0.1362920035418675 and parameters: {'max_depth': 9, 'learning_rate': 0.3661186669360663, 'gamma': 0.9129228225551977, 'n_estimators': 96}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:52,045] Trial 4 finished with value: 0.1362920035418675 and parameters: {'max_depth': 10, 'learning_rate': 0.6195131152351411, 'gamma': 0.9276381383740137, 'n_estimators': 142}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:52,686] Trial 5 finished with value: 0.1362920035418675 and parameters: {'max_depth': 2, 'learning_rate': 0.9662328226030785, 'gamma': 0.6358714755479733, 'n_estimators': 237}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:53,333] Trial 6 finished with value: 0.1362920035418675 and parameters: {'max_depth': 5, 'learning_rate': 0.09863070142672292, 'gamma': 0.6510384026550435, 'n_estimators': 112}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:53,947] Trial 7 finished with value: 0.1362920035418675 and parameters: {'max_depth': 11, 'learning_rate': 0.0993217281569102, 'gamma': 0.14367403032602855, 'n_estimators': 273}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:54,607] Trial 8 finished with value: 0.1362920035418675 and parameters: {'max_depth': 2, 'learning_rate': 0.2181419641405682, 'gamma': 0.788688846263083, 'n_estimators': 293}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:55,231] Trial 9 finished with value: 0.1362920035418675 and parameters: {'max_depth': 10, 'learning_rate': 0.889301889478675, 'gamma': 0.2284032073753376, 'n_estimators': 255}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:55,882] Trial 10 finished with value: 0.1362920035418675 and parameters: {'max_depth': 6, 'learning_rate': 0.479793172849532, 'gamma': 0.34248356715003275, 'n_estimators': 207}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:56,521] Trial 11 finished with value: 0.1362920035418675 and parameters: {'max_depth': 8, 'learning_rate': 0.6819588761688307, 'gamma': 0.4225059241771, 'n_estimators': 64}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:57,153] Trial 12 finished with value: 0.1362920035418675 and parameters: {'max_depth': 7, 'learning_rate': 0.8148129937298401, 'gamma': 0.5752226541303322, 'n_estimators': 211}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:57,804] Trial 13 finished with value: 0.1362920035418675 and parameters: {'max_depth': 12, 'learning_rate': 0.5980712630109944, 'gamma': 0.46438400508343614, 'n_estimators': 182}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:58,453] Trial 14 finished with value: 0.1362920035418675 and parameters: {'max_depth': 7, 'learning_rate': 0.4769901822954647, 'gamma': 0.3279673374347861, 'n_estimators': 121}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:59,082] Trial 15 finished with value: 0.1362920035418675 and parameters: {'max_depth': 4, 'learning_rate': 0.98682425175041, 'gamma': 0.7652783357420145, 'n_estimators': 79}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:25:59,721] Trial 16 finished with value: 0.1362920035418675 and parameters: {'max_depth': 8, 'learning_rate': 0.7790494529074492, 'gamma': 0.5365167404503672, 'n_estimators': 217}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:26:00,350] Trial 17 finished with value: 0.1362920035418675 and parameters: {'max_depth': 6, 'learning_rate': 0.44412328714239957, 'gamma': 0.27764517244828096, 'n_estimators': 134}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:26:01,004] Trial 18 finished with value: 0.1362920035418675 and parameters: {'max_depth': 3, 'learning_rate': 0.9767191834727778, 'gamma': 0.7867227977557961, 'n_estimators': 67}. Best is trial 0 with value: 0.1362920035418675. [I 2022-01-08 08:26:01,679] Trial 19 finished with value: 0.1362920035418675 and parameters: {'max_depth': 9, 'learning_rate': 0.8410670101312083, 'gamma': 0.5215862633670187, 'n_estimators': 224}. Best is trial 0 with value: 0.1362920035418675.
Best model: 0.1362920035418675
Best Parameters: {'max_depth': 7, 'learning_rate': 0.7434376700388832, 'gamma': 0.3746205790870919, 'n_estimators': 233}
Execution time: 81.43442630767822 s
In Optuna, the best model has been found with 0.1362 RMSE score with following best hyper parameters. We will test the selected model in model evaluation section.
from time import time
rn = np.random.seed(100459259)
from sklearn.experimental import enable_halving_search_cv
from sklearn.model_selection import HalvingRandomSearchCV
FACTOR = 2
MAX_RESOURCE_DIVISOR = 4
n_samples = sparse_train.shape[0]
grid_param_xgb = [{'max_depth': range(2, 12, 1),
'n_estimators': range(60, 300, 40),
'learning_rate': [0.05,0.01,0.1,0.3],
'gamma': [0,0.3,0.6,1],
'booster': ['gbtree', 'dart']
}]
start_time = time()
halving_grid_search_xgb = HalvingRandomSearchCV(estimator,resource='n_samples',
min_resources=n_samples//MAX_RESOURCE_DIVISOR,
factor=FACTOR,
param_distributions = grid_param_xgb,
scoring = 'neg_root_mean_squared_error', cv=3,
n_jobs = -1, random_state = rn).fit(sparse_train,label_train)
end_time = time()
halving_xgb_best_model = -halving_grid_search_xgb.best_score_
halving_xgb_best_params = halving_grid_search_xgb.best_params_
hl_xgb_resources = halving_grid_search_xgb.n_resources_
hl_xgb_iterations = halving_grid_search_xgb.n_iterations_
hl_xgb_candidates = halving_grid_search_xgb.n_candidates_
hl_xgb_ex_time = end_time - start_time
print("Best CV Score: {}".format(halving_xgb_best_model))
print("Best parameters: {}".format(halving_xgb_best_params))
print("Resources: {}".format(hl_xgb_resources))
print("Iterations: {}".format(hl_xgb_iterations))
print("n_canditates: {}".format(hl_xgb_candidates))
print("execution time: {}".format(round(hl_xgb_ex_time,4)))
results_xgb = pd.DataFrame(halving_grid_search_xgb.cv_results_)
Best CV Score: 0.1376363226860785
Best parameters: {'n_estimators': 140, 'max_depth': 6, 'learning_rate': 0.05, 'gamma': 0, 'booster': 'dart'}
Resources: [243, 486, 972]
Iterations: 3
n_canditates: [4, 2, 1]
execution time: 8.1326
In Halving RandomSearchCV, the best model has been found with 0.1376 RMSE which is larger than the RMSE achieved by Optuna. We will test both selected models in model evaluation section to see which one is best for the test sample.
Note: In halving RandomSearchSV, the hyper-parameters grid were not given randomly as in Optuna.
## model evaluation
xgb_params = {'booster': 'dart',
'gamma': 0.9597641683283693,
'learning_rate': 0.04397193211151251,
'max_depth': 7,
'n_estimators': 260,
'objective':'reg:squarederror'
}
xgb_params['eval_metric'] = "rmse"
evallist = [(dense_test, 'eval')]
num_round = 1000
bst_optuna = xgb.train(xgb_params, dense_train, num_round, evallist, early_stopping_rounds=10)
[0] eval-rmse:11.0223 Will train until eval-rmse hasn't improved in 10 rounds. [1] eval-rmse:10.5386 [2] eval-rmse:10.0762 [3] eval-rmse:9.63411 [4] eval-rmse:9.21147 [5] eval-rmse:8.80742 [6] eval-rmse:8.42116 [7] eval-rmse:8.0519 [8] eval-rmse:7.69877 [9] eval-rmse:7.36116 [10] eval-rmse:7.03839 [11] eval-rmse:6.7298 [12] eval-rmse:6.43591 [13] eval-rmse:6.15384 [14] eval-rmse:5.88522 [15] eval-rmse:5.62739 [16] eval-rmse:5.38177 [17] eval-rmse:5.14635 [18] eval-rmse:4.92105 [19] eval-rmse:4.70658 [20] eval-rmse:4.50086 [21] eval-rmse:4.30385 [22] eval-rmse:4.11628 [23] eval-rmse:3.93717 [24] eval-rmse:3.76534 [25] eval-rmse:3.60076 [26] eval-rmse:3.44334 [27] eval-rmse:3.29323 [28] eval-rmse:3.15003 [29] eval-rmse:3.01256 [30] eval-rmse:2.88177 [31] eval-rmse:2.7568 [32] eval-rmse:2.63691 [33] eval-rmse:2.52206 [34] eval-rmse:2.41278 [35] eval-rmse:2.30802 [36] eval-rmse:2.20766 [37] eval-rmse:2.11229 [38] eval-rmse:2.02086 [39] eval-rmse:1.93337 [40] eval-rmse:1.85007 [41] eval-rmse:1.7701 [42] eval-rmse:1.69402 [43] eval-rmse:1.62116 [44] eval-rmse:1.55133 [45] eval-rmse:1.48495 [46] eval-rmse:1.42116 [47] eval-rmse:1.36012 [48] eval-rmse:1.30154 [49] eval-rmse:1.24577 [50] eval-rmse:1.19253 [51] eval-rmse:1.14181 [52] eval-rmse:1.09319 [53] eval-rmse:1.04675 [54] eval-rmse:1.00244 [55] eval-rmse:0.960119 [56] eval-rmse:0.919546 [57] eval-rmse:0.880858 [58] eval-rmse:0.844122 [59] eval-rmse:0.80892 [60] eval-rmse:0.77504 [61] eval-rmse:0.743298 [62] eval-rmse:0.712342 [63] eval-rmse:0.683098 [64] eval-rmse:0.655091 [65] eval-rmse:0.628154 [66] eval-rmse:0.602581 [67] eval-rmse:0.577833 [68] eval-rmse:0.554614 [69] eval-rmse:0.532343 [70] eval-rmse:0.510977 [71] eval-rmse:0.49085 [72] eval-rmse:0.471619 [73] eval-rmse:0.453531 [74] eval-rmse:0.436039 [75] eval-rmse:0.419323 [76] eval-rmse:0.403618 [77] eval-rmse:0.388662 [78] eval-rmse:0.374454 [79] eval-rmse:0.36094 [80] eval-rmse:0.347994 [81] eval-rmse:0.335616 [82] eval-rmse:0.32392 [83] eval-rmse:0.312893 [84] eval-rmse:0.302434 [85] eval-rmse:0.292469 [86] eval-rmse:0.282951 [87] eval-rmse:0.273957 [88] eval-rmse:0.265512 [89] eval-rmse:0.257758 [90] eval-rmse:0.250443 [91] eval-rmse:0.243399 [92] eval-rmse:0.236385 [93] eval-rmse:0.230179 [94] eval-rmse:0.224303 [95] eval-rmse:0.218703 [96] eval-rmse:0.213557 [97] eval-rmse:0.208473 [98] eval-rmse:0.203948 [99] eval-rmse:0.199662 [100] eval-rmse:0.195739 [101] eval-rmse:0.192064 [102] eval-rmse:0.188563 [103] eval-rmse:0.185428 [104] eval-rmse:0.182509 [105] eval-rmse:0.179793 [106] eval-rmse:0.177268 [107] eval-rmse:0.174921 [108] eval-rmse:0.172742 [109] eval-rmse:0.17072 [110] eval-rmse:0.168846 [111] eval-rmse:0.167109 [112] eval-rmse:0.165499 [113] eval-rmse:0.16401 [114] eval-rmse:0.162631 [115] eval-rmse:0.161356 [116] eval-rmse:0.160178 [117] eval-rmse:0.159089 [118] eval-rmse:0.158082 [119] eval-rmse:0.157152 [120] eval-rmse:0.156294 [121] eval-rmse:0.155502 [122] eval-rmse:0.15477 [123] eval-rmse:0.154095 [124] eval-rmse:0.153473 [125] eval-rmse:0.152898 [126] eval-rmse:0.152368 [127] eval-rmse:0.151879 [128] eval-rmse:0.151428 [129] eval-rmse:0.151012 [130] eval-rmse:0.150628 [131] eval-rmse:0.150273 [132] eval-rmse:0.149946 [133] eval-rmse:0.149645 [134] eval-rmse:0.149366 [135] eval-rmse:0.149109 [136] eval-rmse:0.148872 [137] eval-rmse:0.148653 [138] eval-rmse:0.14845 [139] eval-rmse:0.148264 [140] eval-rmse:0.148091 [141] eval-rmse:0.147931 [142] eval-rmse:0.147784 [143] eval-rmse:0.147647 [144] eval-rmse:0.147521 [145] eval-rmse:0.147405 [146] eval-rmse:0.147297 [147] eval-rmse:0.146976 [148] eval-rmse:0.146883 [149] eval-rmse:0.146797 [150] eval-rmse:0.146717 [151] eval-rmse:0.146643 [152] eval-rmse:0.146574 [153] eval-rmse:0.146511 [154] eval-rmse:0.146452 [155] eval-rmse:0.146397 [156] eval-rmse:0.146346 [157] eval-rmse:0.146298 [158] eval-rmse:0.146254 [159] eval-rmse:0.146213 [160] eval-rmse:0.146175 [161] eval-rmse:0.14614 [162] eval-rmse:0.146107 [163] eval-rmse:0.146076 [164] eval-rmse:0.146047 [165] eval-rmse:0.14602 [166] eval-rmse:0.145995 [167] eval-rmse:0.145971 [168] eval-rmse:0.14595 [169] eval-rmse:0.145929 [170] eval-rmse:0.14591 [171] eval-rmse:0.145892 [172] eval-rmse:0.145875 [173] eval-rmse:0.14586 [174] eval-rmse:0.145845 [175] eval-rmse:0.145831 [176] eval-rmse:0.145818 [177] eval-rmse:0.145806 [178] eval-rmse:0.145794 [179] eval-rmse:0.145784 [180] eval-rmse:0.145774 [181] eval-rmse:0.145764 [182] eval-rmse:0.145755 [183] eval-rmse:0.145747 [184] eval-rmse:0.145739 [185] eval-rmse:0.145731 [186] eval-rmse:0.145724 [187] eval-rmse:0.145718 [188] eval-rmse:0.145712 [189] eval-rmse:0.145706 [190] eval-rmse:0.1457 [191] eval-rmse:0.145695 [192] eval-rmse:0.14569 [193] eval-rmse:0.145685 [194] eval-rmse:0.145681 [195] eval-rmse:0.145677 [196] eval-rmse:0.145673 [197] eval-rmse:0.145669 [198] eval-rmse:0.145665 [199] eval-rmse:0.145662 [200] eval-rmse:0.145659 [201] eval-rmse:0.145656 [202] eval-rmse:0.145653 [203] eval-rmse:0.14565 [204] eval-rmse:0.145648 [205] eval-rmse:0.145645 [206] eval-rmse:0.145643 [207] eval-rmse:0.145641 [208] eval-rmse:0.145638 [209] eval-rmse:0.145636 [210] eval-rmse:0.145635 [211] eval-rmse:0.145633 [212] eval-rmse:0.145631 [213] eval-rmse:0.145629 [214] eval-rmse:0.145628 [215] eval-rmse:0.145626 [216] eval-rmse:0.145625 [217] eval-rmse:0.145624 [218] eval-rmse:0.145622 [219] eval-rmse:0.145621 [220] eval-rmse:0.14562 [221] eval-rmse:0.145619 [222] eval-rmse:0.145618 [223] eval-rmse:0.145617 [224] eval-rmse:0.145616 [225] eval-rmse:0.145615 [226] eval-rmse:0.145614 [227] eval-rmse:0.145613 [228] eval-rmse:0.145613 [229] eval-rmse:0.145612 [230] eval-rmse:0.145611 [231] eval-rmse:0.14561 [232] eval-rmse:0.14561 [233] eval-rmse:0.145609 [234] eval-rmse:0.145609 [235] eval-rmse:0.145608 [236] eval-rmse:0.145608 [237] eval-rmse:0.145607 [238] eval-rmse:0.145607 [239] eval-rmse:0.145606 [240] eval-rmse:0.145606 [241] eval-rmse:0.145605 [242] eval-rmse:0.145605 [243] eval-rmse:0.145604 [244] eval-rmse:0.145604 [245] eval-rmse:0.145604 [246] eval-rmse:0.145603 [247] eval-rmse:0.145603 [248] eval-rmse:0.145603 [249] eval-rmse:0.145602 [250] eval-rmse:0.145602 [251] eval-rmse:0.145602 [252] eval-rmse:0.145602 [253] eval-rmse:0.145601 [254] eval-rmse:0.145601 [255] eval-rmse:0.145601 [256] eval-rmse:0.145601 [257] eval-rmse:0.145601 [258] eval-rmse:0.1456 [259] eval-rmse:0.1456 [260] eval-rmse:0.1456 [261] eval-rmse:0.1456 [262] eval-rmse:0.1456 [263] eval-rmse:0.145599 [264] eval-rmse:0.145599 [265] eval-rmse:0.145599 [266] eval-rmse:0.145599 [267] eval-rmse:0.145599 [268] eval-rmse:0.145599 [269] eval-rmse:0.145599 [270] eval-rmse:0.145599 [271] eval-rmse:0.145598 [272] eval-rmse:0.145598 [273] eval-rmse:0.145598 [274] eval-rmse:0.145598 [275] eval-rmse:0.145598 [276] eval-rmse:0.145598 [277] eval-rmse:0.145598 [278] eval-rmse:0.145598 [279] eval-rmse:0.145598 [280] eval-rmse:0.145598 [281] eval-rmse:0.145598 Stopping. Best iteration: [271] eval-rmse:0.145598
Even though the best score in Optuna with the training dataset has been found less than in HalvingRandomSearchCV, as seen in above results, the chosen model with less training RMSE could not work very good in test sample. This is beacuse the chosen parameters causes overfitting. Due to that reason, the selected model has higher RMSE in evaluation sample (0.1455).
## model evaluation
xgb_params = {'booster': 'dart',
'gamma': 0,
'learning_rate': 0.05,
'max_depth': 6,
'n_estimators': 140
}
xgb_params['eval_metric'] = "rmse"
evallist = [(dense_test, 'eval')]
num_round = 1000
bst = xgb.train(xgb_params, dense_train, num_round, evallist, early_stopping_rounds=10)
# best model: [254] eval-rmse:0.123379
[0] eval-rmse:10.953 Will train until eval-rmse hasn't improved in 10 rounds. [1] eval-rmse:10.4064 [2] eval-rmse:9.88722 [3] eval-rmse:9.39398 [4] eval-rmse:8.92541 [5] eval-rmse:8.4803 [6] eval-rmse:8.05746 [7] eval-rmse:7.65565 [8] eval-rmse:7.27391 [9] eval-rmse:6.91125 [10] eval-rmse:6.56671 [11] eval-rmse:6.24066 [12] eval-rmse:5.92969 [13] eval-rmse:5.63542 [14] eval-rmse:5.35475 [15] eval-rmse:5.08907 [16] eval-rmse:4.83601 [17] eval-rmse:4.5956 [18] eval-rmse:4.368 [19] eval-rmse:4.15065 [20] eval-rmse:3.94504 [21] eval-rmse:3.74925 [22] eval-rmse:3.56286 [23] eval-rmse:3.38682 [24] eval-rmse:3.21936 [25] eval-rmse:3.05944 [26] eval-rmse:2.90809 [27] eval-rmse:2.7644 [28] eval-rmse:2.62823 [29] eval-rmse:2.49863 [30] eval-rmse:2.37569 [31] eval-rmse:2.25818 [32] eval-rmse:2.14686 [33] eval-rmse:2.04146 [34] eval-rmse:1.94119 [35] eval-rmse:1.8459 [36] eval-rmse:1.75571 [37] eval-rmse:1.66952 [38] eval-rmse:1.58756 [39] eval-rmse:1.5101 [40] eval-rmse:1.43628 [41] eval-rmse:1.36606 [42] eval-rmse:1.29945 [43] eval-rmse:1.23621 [44] eval-rmse:1.17588 [45] eval-rmse:1.11946 [46] eval-rmse:1.06539 [47] eval-rmse:1.0136 [48] eval-rmse:0.965461 [49] eval-rmse:0.919384 [50] eval-rmse:0.875742 [51] eval-rmse:0.834224 [52] eval-rmse:0.794514 [53] eval-rmse:0.757106 [54] eval-rmse:0.721541 [55] eval-rmse:0.687988 [56] eval-rmse:0.655816 [57] eval-rmse:0.625495 [58] eval-rmse:0.596683 [59] eval-rmse:0.56933 [60] eval-rmse:0.543515 [61] eval-rmse:0.519204 [62] eval-rmse:0.495821 [63] eval-rmse:0.473762 [64] eval-rmse:0.453015 [65] eval-rmse:0.433337 [66] eval-rmse:0.41462 [67] eval-rmse:0.397002 [68] eval-rmse:0.380194 [69] eval-rmse:0.364116 [70] eval-rmse:0.349157 [71] eval-rmse:0.335108 [72] eval-rmse:0.32185 [73] eval-rmse:0.30941 [74] eval-rmse:0.297502 [75] eval-rmse:0.286318 [76] eval-rmse:0.275918 [77] eval-rmse:0.266227 [78] eval-rmse:0.256881 [79] eval-rmse:0.248043 [80] eval-rmse:0.239793 [81] eval-rmse:0.232056 [82] eval-rmse:0.224917 [83] eval-rmse:0.218047 [84] eval-rmse:0.211765 [85] eval-rmse:0.20605 [86] eval-rmse:0.200271 [87] eval-rmse:0.195114 [88] eval-rmse:0.190376 [89] eval-rmse:0.185966 [90] eval-rmse:0.18165 [91] eval-rmse:0.177795 [92] eval-rmse:0.174154 [93] eval-rmse:0.170919 [94] eval-rmse:0.167938 [95] eval-rmse:0.165056 [96] eval-rmse:0.16239 [97] eval-rmse:0.159901 [98] eval-rmse:0.157473 [99] eval-rmse:0.154944 [100] eval-rmse:0.153064 [101] eval-rmse:0.151156 [102] eval-rmse:0.149435 [103] eval-rmse:0.147847 [104] eval-rmse:0.146424 [105] eval-rmse:0.145165 [106] eval-rmse:0.143808 [107] eval-rmse:0.142625 [108] eval-rmse:0.141577 [109] eval-rmse:0.140519 [110] eval-rmse:0.139644 [111] eval-rmse:0.138881 [112] eval-rmse:0.138042 [113] eval-rmse:0.137239 [114] eval-rmse:0.136575 [115] eval-rmse:0.135853 [116] eval-rmse:0.135332 [117] eval-rmse:0.134866 [118] eval-rmse:0.134235 [119] eval-rmse:0.133869 [120] eval-rmse:0.133522 [121] eval-rmse:0.133056 [122] eval-rmse:0.132616 [123] eval-rmse:0.132361 [124] eval-rmse:0.132045 [125] eval-rmse:0.131644 [126] eval-rmse:0.131463 [127] eval-rmse:0.131115 [128] eval-rmse:0.130871 [129] eval-rmse:0.130522 [130] eval-rmse:0.130059 [131] eval-rmse:0.129855 [132] eval-rmse:0.129581 [133] eval-rmse:0.129398 [134] eval-rmse:0.129059 [135] eval-rmse:0.128814 [136] eval-rmse:0.128631 [137] eval-rmse:0.128499 [138] eval-rmse:0.128359 [139] eval-rmse:0.128159 [140] eval-rmse:0.128014 [141] eval-rmse:0.127762 [142] eval-rmse:0.127659 [143] eval-rmse:0.127562 [144] eval-rmse:0.127498 [145] eval-rmse:0.12734 [146] eval-rmse:0.12724 [147] eval-rmse:0.127261 [148] eval-rmse:0.127108 [149] eval-rmse:0.127068 [150] eval-rmse:0.126865 [151] eval-rmse:0.126762 [152] eval-rmse:0.126764 [153] eval-rmse:0.126711 [154] eval-rmse:0.12666 [155] eval-rmse:0.126556 [156] eval-rmse:0.12652 [157] eval-rmse:0.126374 [158] eval-rmse:0.126296 [159] eval-rmse:0.126222 [160] eval-rmse:0.126205 [161] eval-rmse:0.126181 [162] eval-rmse:0.126185 [163] eval-rmse:0.12602 [164] eval-rmse:0.125981 [165] eval-rmse:0.125952 [166] eval-rmse:0.125937 [167] eval-rmse:0.125892 [168] eval-rmse:0.125839 [169] eval-rmse:0.125773 [170] eval-rmse:0.125698 [171] eval-rmse:0.12555 [172] eval-rmse:0.125499 [173] eval-rmse:0.125427 [174] eval-rmse:0.12539 [175] eval-rmse:0.125372 [176] eval-rmse:0.12525 [177] eval-rmse:0.125206 [178] eval-rmse:0.125199 [179] eval-rmse:0.125091 [180] eval-rmse:0.125089 [181] eval-rmse:0.125045 [182] eval-rmse:0.125038 [183] eval-rmse:0.125044 [184] eval-rmse:0.124946 [185] eval-rmse:0.124919 [186] eval-rmse:0.124904 [187] eval-rmse:0.124862 [188] eval-rmse:0.12476 [189] eval-rmse:0.124755 [190] eval-rmse:0.124716 [191] eval-rmse:0.124657 [192] eval-rmse:0.124653 [193] eval-rmse:0.124625 [194] eval-rmse:0.124598 [195] eval-rmse:0.124617 [196] eval-rmse:0.124642 [197] eval-rmse:0.124578 [198] eval-rmse:0.124535 [199] eval-rmse:0.124447 [200] eval-rmse:0.124391 [201] eval-rmse:0.124357 [202] eval-rmse:0.124273 [203] eval-rmse:0.124269 [204] eval-rmse:0.124272 [205] eval-rmse:0.124267 [206] eval-rmse:0.124241 [207] eval-rmse:0.124215 [208] eval-rmse:0.124217 [209] eval-rmse:0.124209 [210] eval-rmse:0.124228 [211] eval-rmse:0.124213 [212] eval-rmse:0.124166 [213] eval-rmse:0.124134 [214] eval-rmse:0.124079 [215] eval-rmse:0.124055 [216] eval-rmse:0.124026 [217] eval-rmse:0.124014 [218] eval-rmse:0.124016 [219] eval-rmse:0.12402 [220] eval-rmse:0.124006 [221] eval-rmse:0.123998 [222] eval-rmse:0.123932 [223] eval-rmse:0.123887 [224] eval-rmse:0.123887 [225] eval-rmse:0.123902 [226] eval-rmse:0.123911 [227] eval-rmse:0.123897 [228] eval-rmse:0.123869 [229] eval-rmse:0.1239 [230] eval-rmse:0.123871 [231] eval-rmse:0.123776 [232] eval-rmse:0.123735 [233] eval-rmse:0.123711 [234] eval-rmse:0.123713 [235] eval-rmse:0.123689 [236] eval-rmse:0.123694 [237] eval-rmse:0.123692 [238] eval-rmse:0.123678 [239] eval-rmse:0.123675 [240] eval-rmse:0.123657 [241] eval-rmse:0.123635 [242] eval-rmse:0.123614 [243] eval-rmse:0.123592 [244] eval-rmse:0.123562 [245] eval-rmse:0.123548 [246] eval-rmse:0.123541 [247] eval-rmse:0.123555 [248] eval-rmse:0.12352 [249] eval-rmse:0.123504 [250] eval-rmse:0.123494 [251] eval-rmse:0.123479 [252] eval-rmse:0.123418 [253] eval-rmse:0.123416 [254] eval-rmse:0.123379 [255] eval-rmse:0.123423 [256] eval-rmse:0.123409 [257] eval-rmse:0.123444 [258] eval-rmse:0.123448 [259] eval-rmse:0.12347 [260] eval-rmse:0.123456 [261] eval-rmse:0.123399 [262] eval-rmse:0.123394 [263] eval-rmse:0.12342 [264] eval-rmse:0.123416 Stopping. Best iteration: [254] eval-rmse:0.123379
By using RandomSearchCV for hyper parameter tuning of XGBModel, we got higher RMSE score for training sample compared to Optuna. However, the test-RMSE has been found lower than Optuna's test-RMSE score.
Even though the train-RMSE score was higher than in the model using Optuna, the selected model from HalvingRandomSearchCV worked better in test sample. Test-rmse has been calculated 0.1233. Therefore, for prediction, the model with less eval-RMSE will be used.
In XGBoost, it is possible to visualize each feature importance with its weight, which is useful to distinguish the relevant attributes.
feature_important = bst.get_score(importance_type='weight')
keys = list(feature_important.keys())
values = list(feature_important.values())
## visual 1
data_xgb = pd.DataFrame(data=values, index=keys, columns=["score"]).sort_values(by = "score", ascending=False)
p1 = data_xgb.plot(kind='bar',legend=False, alpha=1, color = "darkred", grid = False)
p1.tick_params(axis='y', labelsize=10)
p1.tick_params(axis='x', labelsize=8)
p1.set_title("Feature Importance with XGBoost", fontsize=18)
p1.set_ylabel("Features", fontsize=15)
p1.set_xlabel("Scores", fontsize=15)
p1.legend(fontsize=15)
plt.tight_layout()
plt.show()
## visual 2
p2 = xgb.plot_importance(bst, importance_type='weight', height = 0.6, show_values=True, max_num_features= 10, grid=False, color= "mediumblue")
p2.tick_params(axis='y', labelsize=12)
p2.set_title('Feature Importance with Weight', fontsize=18)
p2.set_ylabel("Features", fontsize=15)
p2.set_xlabel("Scores", fontsize=15)
p2.legend(fontsize=15)
plt.show()
No handles with labels found to put in legend.
## Prediction with the best model
ypred = bst.predict(dense_test, ntree_limit=bst.best_ntree_limit)
ypred_train = bst.predict(dense_train, ntree_limit=bst.best_ntree_limit)
#evolution of the test sample
from sklearn.metrics import mean_squared_error
mse = mean_squared_error(label_test, ypred)
rmse = np.sqrt(mse)
print('Root Mean Squared Error (RMSE): %.4f' % rmse)
# Scatter Plot
x = label_test
y = ypred
lineStart = label_test.min()
lineEnd = ypred.max()
plt.style.use('seaborn')
plt.figure()
plt.scatter(x, y, color = 'k', alpha=0.5, linewidths=3, label='data')
plt.plot([lineStart, lineEnd], [lineStart, lineEnd], 'k-', color = 'r', label='reference line')
plt.title("Model Performance Graph-XGBoost(Test set)")
plt.xlabel("Sale Price")
plt.ylabel("Pred Sale Price")
plt.legend()
plt.show()
Root Mean Squared Error (RMSE): 0.1234
## model evaluation
sparse_final = scipy.sparse.csr_matrix(X_comp)
label_final = y_comp
dense_final = xgb.DMatrix(sparse_final, label=label_final, feature_names=features)
label_final = bst.predict(dense_final, ntree_limit=bst.best_ntree_limit)
SalePrice_xgb = np.exp(label_final)
Id = list(range(1461,2920))
pred_df_xgb = pd.DataFrame({"Id": Id, "SalePrice": SalePrice_xgb})
pred_df_xgb
| Id | SalePrice | |
|---|---|---|
| 0 | 1461 | 117575.296875 |
| 1 | 1462 | 164858.234375 |
| 2 | 1463 | 184130.093750 |
| 3 | 1464 | 192030.968750 |
| 4 | 1465 | 185332.312500 |
| ... | ... | ... |
| 1454 | 2915 | 77856.210938 |
| 1455 | 2916 | 81660.031250 |
| 1456 | 2917 | 157924.671875 |
| 1457 | 2918 | 110760.406250 |
| 1458 | 2919 | 229340.750000 |
1459 rows × 2 columns
from google.colab import drive
drive.mount('/drive')
Drive already mounted at /drive; to attempt to forcibly remount, call drive.mount("/drive", force_remount=True).
pred_df_xgb.to_csv('/drive/My Drive/Predictions_XGB.csv',index=False)
For improvement, XGBoost model has been used to predict the Sale Price. Best hyper-parameters for XGBoost model have been tried. These have been found by HalvingRandomSearchCV and Optuna. After doing model evaluation in test sample, XGBoost model has been executed with the best hyper-parameter given by Halving random seach CV. The test-RMSE score calculated is 0.1234 which is quite similar but smaller than the solution found with histgradient boosting model (0.1256).
Optuna documentation \ https://optuna.readthedocs.io/ \ https://scikit-learn.org/0.15/modules/scaling_strategies.html \ https://medium.com/optuna/an-introduction-to-the-implementation-of-optuna-a-hyperparameter-optimization-framework \ https://scikit-learn.org/stable/modules/grid_search.html#searching-for-optimal-parameters-with-successive-halving \ https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.