0% found this document useful (0 votes)
15 views11 pages

Indi - Colab

The document outlines a machine learning workflow using Python, focusing on evaluating and tuning models for classification tasks. It includes functions for calculating evaluation metrics, handling imbalanced data with oversampling techniques, and performing hyperparameter tuning using grid search. The document also demonstrates the use of a baseline model and evaluates its performance on a dataset containing various grades.

Uploaded by

tranthuymy68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

Indi - Colab

The document outlines a machine learning workflow using Python, focusing on evaluating and tuning models for classification tasks. It includes functions for calculating evaluation metrics, handling imbalanced data with oversampling techniques, and performing hyperparameter tuning using grid search. The document also demonstrates the use of a baseline model and evaluates its performance on a dataset containing various grades.

Uploaded by

tranthuymy68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

import logging

logging.basicConfig()
logging.getLogger("SKLEARNEX").setLevel(logging.ERROR)

import json
import gzip
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn.metrics import precision_recall_fscore_support, classification_report


from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.model_selection import cross_val_predict

from IPython.display import display

def groupby_labels(y, yhat):


"""Based on https://stackoverflow.com/questions/38013778/is-there-any-numpy-group-by-function
"""
m = np.stack([y, yhat]).T
m = m[m[:, 0].argsort()]
grouped_preds = np.split(m[:, 1], np.unique(m[:, 0], return_index=True)[1])[1:]
labels = np.unique(m[:, 0])
return labels, grouped_preds

def mae_macro(y, yhat):


"""Macroaveraged MAE
"""
labels, preds = groupby_labels(y, yhat)
mean_diff = np.array([np.abs(label - pred).mean() for label, pred in zip(labels, preds)]).mean()
return mean_diff

def rmse_macro(y, yhat):


"""Macroaveraged RMSE
"""
labels, preds = groupby_labels(y, yhat)
mean_diff = np.array([np.power(label - pred, 2).mean() for label, pred in zip(labels, preds)]).mean()
return np.sqrt(mean_diff)

def evaluate_model(model, ytest, Xtest):


"""Given a trained model and test data, generate predictions
and print a report with evaluation results
"""
yhat = model.predict(Xtest)
print(classification_report(ytest, yhat, zero_division=0))
rmse = rmse_macro(ytest, yhat)
print(f"{'Macro RMSE':18} {rmse:.3}")
mae = mae_macro(ytest, yhat)
print(f"{'Macro MAE':18} {mae:.3}")

def print_cv_results(grid_search, col_width=100, max_rows=10):


"""Given a grid search object, print a table with the
cross-validation results
"""
results = pd.DataFrame(grid_search.cv_results_
)[['params', 'mean_train_score', 'mean_test_score']]

results["mean_train_score"] = -results["mean_train_score"]
results["mean_test_score"] = -results["mean_test_score"]

results["diff, %"] = 100*(results["mean_train_score"]-results["mean_test_score"]


)/results["mean_train_score"]

pd.set_option('display.max_colwidth', col_width)
pd.set_option('display.min_rows', max_rows)
pd.set_option('display.max_rows', max_rows)
display(results.sort_values('mean_test_score', ascending=True))

# create a scoring function


from sklearn.metrics import make_scorer

neg_rmse_macro = make_scorer(rmse_macro, greater_is_better=False)


!pip install scikit-optimize

Collecting scikit-optimize
Downloading scikit_optimize-0.10.2-py2.py3-none-any.whl.metadata (9.7 kB)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.10/dist-packages (from scikit-optimize) (1.4.2)
Collecting pyaml>=16.9 (from scikit-optimize)
Downloading pyaml-25.1.0-py3-none-any.whl.metadata (12 kB)
Requirement already satisfied: numpy>=1.20.3 in /usr/local/lib/python3.10/dist-packages (from scikit-optimize) (1.26.4)
Requirement already satisfied: scipy>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from scikit-optimize) (1.13.1)
Requirement already satisfied: scikit-learn>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-optimize) (1.6.0)
Requirement already satisfied: packaging>=21.3 in /usr/local/lib/python3.10/dist-packages (from scikit-optimize) (24.2)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.10/dist-packages (from pyaml>=16.9->scikit-optimize) (6.0.2)
Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=1.0.0->sc
Downloading scikit_optimize-0.10.2-py2.py3-none-any.whl (107 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 107.8/107.8 kB 3.0 MB/s eta 0:00:00
Downloading pyaml-25.1.0-py3-none-any.whl (26 kB)
Installing collected packages: pyaml, scikit-optimize
Successfully installed pyaml-25.1.0 scikit-optimize-0.10.2

Load data

import pandas as pd # Import the pandas library and give it the alias 'pd'

trainset = pd.read_csv("/content/trainsetforbigdata.csv")
testset = pd.read_csv("/content/testsetforbigdata.csv")

trainset['grade'].value_counts()

count

grade

7 7044

8 4696

9 1920

6 1599

10 741

11 193

5 185

12 25

4 19

1 1

13 1

3 1

dtype: int64

Xtrain = trainset.drop("grade", axis=1)


ytrain = trainset["grade"].copy()
Xtest = testset.drop("grade", axis=1)
ytest = testset["grade"].copy()

Xtrain.shape, Xtest.shape

((16425, 15), (4323, 15))

3.Baseline
We'll use a simple baseline: dummy classi er :

from sklearn.dummy import DummyClassifier

dummy_clf = DummyClassifier(strategy="most_frequent")
dummy_clf.fit(Xtrain, ytrain)
yhat_train = dummy_clf.predict(Xtrain)

evaluate_model(dummy_clf, ytrain, Xtrain)

precision recall f1-score support

1 0.00 0.00 0.00 1


3 0.00 0.00 0.00 1
4 0.00 0.00 0.00 19
5 0.00 0.00 0.00 185
6 0.00 0.00 0.00 1599
7 0.43 1.00 0.60 7044
8 0.00 0.00 0.00 4696
9 0.00 0.00 0.00 1920
10 0.00 0.00 0.00 741
11 0.00 0.00 0.00 193
12 0.00 0.00 0.00 25
13 0.00 0.00 0.00 1

accuracy 0.43 16425


macro avg 0.04 0.08 0.05 16425
weighted avg 0.18 0.43 0.26 16425

Macro RMSE 3.62


Macro MAE 3.08

Model development

4.1 Unbalanced data - linear SVC

from sklearn.model_selection import GridSearchCV


from sklearn.svm import LinearSVC

lsvm = LinearSVC(random_state=7, max_iter=10000)

param_grid = {
'C': [0.001, 0.01, 0.1, 1, 10]
}

lsvc_grid_search = GridSearchCV(lsvm, param_grid, cv=10,


scoring=neg_rmse_macro,
return_train_score=True)
lsvc_grid_search.fit(Xtrain, ytrain)

print_cv_results(lsvc_grid_search, col_width=100, max_rows=150)

/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805: UserWarning: The least populated class in y h


warnings.warn(
params mean_train_score mean_test_score diff, %

4 {'C': 10} 2.010335 1.738254 13.534114

3 {'C': 1} 2.446453 1.784443 27.059985

2 {'C': 0.1} 2.453444 1.791716 26.971398

1 {'C': 0.01} 2.483156 1.861268 25.044227

0 {'C': 0.001} 2.818087 2.023574 28.193332

# cross-validation confusion matrix, training data


yhat = cross_val_predict(lsvc_grid_search.best_estimator_, Xtrain, ytrain, cv=10)
ConfusionMatrixDisplay.from_predictions(ytrain, yhat,
labels=lsvc_grid_search.best_estimator_.classes_,
normalize="true",
cmap=plt.cm.Blues);
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805: UserWarning: The least populated class in y h
warnings.warn(

4.2 Class balancing - based on the linear SVC model , we will do hyperparameter tuning with random over sampler

from imblearn.pipeline import Pipeline


from imblearn.over_sampling import SMOTE, RandomOverSampler

pipeline = Pipeline([
('cb', RandomOverSampler(random_state=7)),
('lsvc', LinearSVC(random_state=7, max_iter=10000))
])

param_grid = [
{
'cb__sampling_strategy': ["auto"],
'lsvc__C': [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10],
},
]

cb_grid_search = GridSearchCV(pipeline, param_grid, cv=10,


scoring=neg_rmse_macro,
return_train_score=True)

cb_grid_search.fit(Xtrain, ytrain)

print_cv_results(cb_grid_search, col_width=100)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805: UserWarning: The least populated class in y h
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
# cross-validation confusion matrix on the training data
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
yhat = warnings.warn(
cross_val_predict(cb_grid_search.best_estimator_, Xtrain, ytrain, cv=10)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
ConfusionMatrixDisplay.from_predictions(ytrain, yhat,
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
labels=cb_grid_search.best_estimator_.classes_,
warnings.warn( normalize="true",
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
cmap=plt.cm.Blues); FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3 10/dist packages/sklearn/utils/ tags py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805:
warnings.warn( UserWarning: The least populated class in y h
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
warnings.warn( FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
4.3 Logistic regression
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
warnings.warn( FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn( FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
from /usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
sklearn.linear_model import LogisticRegression FutureWarning: `BaseEstimator._check_n_features` is deprecated
from /usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
sklearn.metrics
warnings.warn( import ConfusionMatrixDisplay FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
from /usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
sklearn.model_selection import cross_val_predict FutureWarning: `BaseEstimator._check_feature_names` is deprecat
import warnings.warn(
matplotlib.pyplot as plt
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
# Define the parameter grid for Logistic Regression
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
param_grid = [ FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
{'C': [0.1, 1, 10, 100],
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
'solver': ['liblinear', 'lbfgs']}
warnings.warn(
] /usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
# Initialize the Logistic Regression classifier
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
log_regwarnings.warn(
= LogisticRegression(max_iter=1000, random_state=42)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
# Initialize the GridSearchCV
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
log_reg_grid_search = GridSearchCV(log_reg, param_grid, cv=10, FutureWarning: The RandomOverSampler or classes from whi
warnings.warn( scoring='f1_macro', return_train_score=True)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
# Perform the grid search on the training set
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
log_reg_grid_search.fit(Xtrain,
warnings.warn( ytrain)
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
i (
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: UserWarning:
FutureWarning: The least populated
The RandomOverSampler class
or classes in y
from h
whi
warnings.warn(
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
▸ GridSearchCV FutureWarning: The RandomOverSampler or classes from whi
warnings.warn( i ?
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
▸warnings.warn(
best_estimator_:
LogisticRegression
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
▸ LogisticRegression ?
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
# training and validation RMSE
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
print_cv_results(log_reg_grid_search, col_width=100)
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn( params mean_train_score mean_test_score diff, %
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
5 warnings.warn(
{'C': 10, 'solver': 'lbfgs'} -0.453283 -0.398510 12.083681
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
3 {'C': 1, 'solver': 'lbfgs'} -0.343640 -0.394325 -14.749376
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
7 {'C': 100, 'solver': 'lbfgs'} -0.513432 -0.390429 23.957006 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
1 {'C': 0.1, 'solver': 'lbfgs'} -0.283365 -0.346313 -22.214245 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
6 {'C': 100, 'solver': 'liblinear'} -0.184973 FutureWarning: `BaseEstimator._check_n_features` is deprecated
-0.213747 -15.555387
warnings.warn(
4 {'C': 10, 'solver': 'liblinear'} -0.181816
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: -0.207062 -13.885188
FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
2 {'C': 1, 'solver': 'liblinear'} -0.166541 -0.206610 -24.059198
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
0 {'C': 0.1, 'solver': 'liblinear'} -0.160519 -0.199989 -24.588969
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
# Perform cross-validation predictions on the training data
warnings.warn(
yhat /usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
= cross_val_predict(log_reg_grid_search.best_estimator_, Xtrain, ytrain, cv=10)
FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
# Plot the confusion matrix
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
ConfusionMatrixDisplay.from_predictions(ytrain, yhat,
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
labels=log_reg_grid_search.best_estimator_.classes_,
warnings.warn( normalize="true",
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
cmap=plt.cm.Blues) FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
plt.show()
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805: UserWarning: The least populated class in y h
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
4.4 Random forest
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
unbalanced data:
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
from sklearn.model_selection import GridSearchCV
from /usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
timeit import default_timer as timer # Import the timer function FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
start =warnings.warn(
timer()
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn( import RandomForestClassifier
from sklearn.ensemble
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
# ... rest of your code
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
from sklearn.model_selection import GridSearchCV
warnings.warn(
from timeit import default_timer as timer # Import the timer function
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
from datetime import timedelta # Import timedelta
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
start =warnings.warn(
timer()
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn( import RandomForestClassifier
from sklearn.ensemble
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
rf = RandomForestClassifier(random_state=7, max_depth=40, min_samples_split=5)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
hp_grid = {
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
'n_estimators': [100, 200, 500],
warnings.warn(
'max_features': ["sqrt", 0.5],
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
'max_samples': [None, 0.5],
warnings.warn(
} /usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
# we'll use 5-fold cross-validation
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
grid_search = GridSearchCV(rf, hp_grid, cv=5,
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
scoring='f1_macro', FutureWarning: The RandomOverSampler or classes from whi
warnings.warn( return_train_score=True, verbose=2)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
grid_search.fit(Xtrain, ytrain)
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
print("Execution time HH:MM:SS:", timedelta(seconds=timer() - start))
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: # Use timedelta
FutureWarning: to format execution time
`BaseEstimator._check_feature_names` is deprecat
warnings.warn(
Fitting 5 folds for each of 12 candidates, totalling 60 fits
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805:
warnings.warn( UserWarning: The least populated class in y h
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
[CV] END max_features=sqrt, max_samples=None, n_estimators=100; total time=
warnings.warn( 4.7s
[CV] END max_features=sqrt, max_samples=None, n_estimators=100; total
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 3.6s The RandomOverSampler or classes from whi
FutureWarning:
[CV] END max_features=sqrt, max_samples=None, n_estimators=100; total time=
warnings.warn( 3.6s
[CV] END max_features=sqrt, max_samples=None, n_estimators=100;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= `BaseEstimator._check_n_features`
FutureWarning: 4.6s is deprecated
[CV] END max_features=sqrt, max_samples=None, n_estimators=100; total time=
warnings.warn( 3.5s
[CV] END max_features=sqrt, max_samples=None, n_estimators=200;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: total time= `BaseEstimator._check_feature_names`
FutureWarning: 9.0s is deprecat
[CV] END max_features=sqrt, max_samples=None, n_estimators=200; total time=
warnings.warn( 7.1s
[CV] END max_features=sqrt, max_samples=None, n_estimators=200; total
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 8.1s The RandomOverSampler or classes from whi
FutureWarning:
[CV] END max_features=sqrt, max_samples=None, n_estimators=200; total time=
warnings.warn( 7.3s
[CV] END max_features=sqrt, max_samples=None, n_estimators=200; total
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 7.8s The RandomOverSampler or classes from whi
FutureWarning:
[CV] END max_features=sqrt, max_samples=None, n_estimators=500; total time= 19.4s
warnings.warn(
[CV] END max_features=sqrt, max_samples=None, n_estimators=500; total
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 18.8s The RandomOverSampler or classes from whi
FutureWarning:
[CV] END max_features=sqrt, max_samples=None, n_estimators=500; total time= 19.4s
warnings.warn(
[CV] END max_features=sqrt, max_samples=None, n_estimators=500;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= `BaseEstimator._check_n_features`
FutureWarning: 18.8s is deprecated
[CV] END max_features=sqrt, max_samples=None, n_estimators=500; total time= 19.7s
warnings.warn(
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=100;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: total time= `BaseEstimator._check_feature_names`
FutureWarning: 2.3s is deprecat
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=100; total time=
warnings.warn( 2.3s
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=100; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 2.3s The RandomOverSampler or classes from whi
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=100; total time=
warnings.warn( 2.8s
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=100; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 2.8s The RandomOverSampler or classes from whi
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 4.7s
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=200; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 5.0s The RandomOverSampler or classes from whi
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 5.0s
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=200;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= `BaseEstimator._check_n_features`
FutureWarning: 4.6s is deprecated
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 5.6s
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=500;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: total time= `BaseEstimator._check_feature_names`
FutureWarning: 12.6s is deprecat
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=500; total time= 12.8s
warnings.warn(
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=500; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 12.5s The RandomOverSampler or classes from whi
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=500; total time= 12.5s
warnings.warn(
[CV] END max_features=sqrt, max_samples=0.5, n_estimators=500; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 12.5s The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=None, n_estimators=100; total time=
warnings.warn( 7.2s
[CV] END max_features=0.5, max_samples=None, n_estimators=100; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 8.1s The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=None, n_estimators=100; total time=
warnings.warn( 7.9s
[CV] END max_features=0.5, max_samples=None, n_estimators=100;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= `BaseEstimator._check_n_features`
FutureWarning: 7.2s is deprecated
[CV] END max_features=0.5,
warnings.warn( max_samples=None, n_estimators=100; total time= 8.1s
[CV] END max_features=0.5, max_samples=None, n_estimators=200;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: total time= `BaseEstimator._check_feature_names`
FutureWarning: 15.3s is deprecat
[CV] END max_features=0.5, max_samples=None, n_estimators=200; total time= 15.4s
warnings.warn(
[CV] END max_features=0.5, max_samples=None, n_estimators=200; total time= 15.2s
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=None, n_estimators=200; total time= 15.6s
warnings.warn(
[CV] END max_features=0.5, max_samples=None, n_estimators=200; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 15.7s The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=None, n_estimators=500; total time= 38.5s
warnings.warn(
[CV] END max_features=0.5, max_samples=None, n_estimators=500; totalFutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: time= 38.2s The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=None, n_estimators=500; total time= 37.6s
warnings.warn(
[CV] END max_features=0.5, max_samples=None, n_estimators=500;
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= 38.2s
FutureWarning: `BaseEstimator._check_n_features` is deprecated
[CV] END max_features=0.5, max_samples=None, n_estimators=500; total time= 38.5s
warnings.warn(
[CV]
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: 5.2s
END max_features=0.5, max_samples=0.5, n_estimators=100; total time= `BaseEstimator. check feature names` is deprecat
/ / / /py / p g / / py g _ _ _ p
[CV] END max_features=0.5, max_samples=0.5, n_estimators=100; total time=
warnings.warn( 4.5s
[CV] END max_features=0.5, max_samples=0.5, n_estimators=100; total time=
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: 5.2s
FutureWarning: The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=0.5, n_estimators=100; total time=
warnings.warn( 4.7s
[CV] END max_features=0.5, max_samples=0.5, n_estimators=100; total time=
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: 4.4s
FutureWarning: The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 9.9s
[CV] END max_features=0.5, max_samples=0.5, n_estimators=200; total time=
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: 9.9s
FutureWarning: The RandomOverSampler or classes from whi
[CV] END max_features=0.5, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 9.3s
[CV] END max_features=0.5, max_samples=0.5, n_estimators=200;FutureWarning:
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: total time= 9.2s
`BaseEstimator._check_n_features` is deprecated
[CV] END max_features=0.5, max_samples=0.5, n_estimators=200; total time=
warnings.warn( 9.9s
[ ]
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
cv_results = pd.DataFrame(grid_search.cv_results_)[['params', 'mean_train_score', 'mean_test_score']]
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
cv_results["diff, %"] = 100*(cv_results["mean_train_score"]-cv_results["mean_test_score"] FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
)/cv_results["mean_train_score"]
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
pd.set_option('display.max_colwidth', 100)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
cv_results.sort_values('mean_test_score',
warnings.warn( ascending=False)
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn( params mean_train_score mean_test_score diff, %
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
8warnings.warn(
{'max_features': 0.5, 'max_samples': None, 'n_estimators': 500} 0.997563 0.493076 50.571978
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
7warnings.warn(
{'max_features': 0.5, 'max_samples': None, 'n_estimators': 200} 0.995720 0.492912 50.496893
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
6warnings.warn(
{'max_features': 0.5, 'max_samples': None, 'n_estimators': 100} 0.994789 0.492418 50.500210
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
2 {'max_features': 'sqrt', 'max_samples': None, 'n_estimators': 500} 0.995538 0.479189 51.866392
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
0 {'max_features': 'sqrt', 'max_samples': None, 'n_estimators': 100} FutureWarning:
0.990357 `BaseEstimator._check_n_features`
0.478270 51.707338 is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
... ... FutureWarning:
... `BaseEstimator._check_feature_names`
... ... is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
9 {'max_features': 0.5, 'max_samples': 0.5, 'n_estimators': 100} FutureWarning:
0.659287 The RandomOverSampler
0.472108 28.391082 or classes from whi
warnings.warn(
11 {'max_features': 0.5, 'max_samples': 0.5, 'n_estimators': 500} 0.663103 0.469791 29.152683
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
3 {'max_features': 'sqrt', 'max_samples': 0.5, 'n_estimators': 100} 0.669981 0.465184 30.567638
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
5warnings.warn(
{'max_features': 'sqrt', 'max_samples': 0.5, 'n_estimators': 500} 0.663344 0.463179 30.175101
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
4warnings.warn(
{'max_features': 'sqrt', 'max_samples': 0.5, 'n_estimators': 200} 0.705286 0.451862 35.932176
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
12 warnings.warn(
rows × 4 columns
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
# cross-validation confusion matrix on the training data FutureWarning: The RandomOverSampler or classes from whi
yhat = warnings.warn(
cross_val_predict(grid_search.best_estimator_, Xtrain, ytrain, cv=10)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
ConfusionMatrixDisplay.from_predictions(ytrain, yhat,
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
labels=grid_search.best_estimator_.classes_,
warnings.warn(
normalize="true",
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn( cmap=plt.cm.Blues);
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
/usr/local/lib/python3.10/dist-packages/sklearn/model_selection/_split.py:805:
warnings.warn( UserWarning: The least populated class in y h
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
5. Evaluate model
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings warn(
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
5.1 Unbalanced linear SVC
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
# Unbalanced linear SVC FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
evaluate_model(lsvc_grid_search.best_estimator_, ytest, Xtest)
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn( precision recall f1-score support
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
1 0.00 0.00 0.00 0
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
4 0.00 0.00 0.00 6 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
5 0.00 0.00 0.00 38
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
6 0.48 0.04 0.08 391 FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
7 0.62 0.89 0.73 1842
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493:
8 0.52 0.53 0.52 1220 FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
9 0.34 0.24 0.28 513
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
10 0.23 0.07 0.11 213 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
11 0.25 0.01 0.02 80
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
12 1.00 0.06 0.11 18 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
13 0.00 0.00 0.00 2
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
accuracy 0.56 4323
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
macro avg 0.31 0.17 0.17 4323 FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
weighted avg 0.52 0.56 0.51 4323
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
Macro RMSE 1.77
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354:
Macro MAE 1.47 FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
5.2 Linear SVC - Random over sampler
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
# /usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
linear SVC - Random over sampler FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
evaluate_model(cb_grid_search.best_estimator_, ytest, Xtest)
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
precision recall f1-score support
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
1 0.00 0.00 0.00 0
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
4 0.03 0.50 0.06 6
warnings.warn(
5 0.07 0.45 0.12 38
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
6 0.24 0.59 0.34 391
warnings.warn(
7 0.62 0.36 0.46 1842
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
8 0.49 0.35 0.41 1220
warnings.warn(
9 0.34 0.31 0.32 513
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
10 0.14 0.10 0.12 213
warnings.warn(
11 0.09 0.28 0.13 80
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
12 0.08 0.94 0.15 18
warnings.warn(
13 0.00 0.00 0.00 2
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
accuracy 0.36 4323
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
macro avg 0.19 0.35 0.19 4323
warnings.warn(
weighted avg 0.47 0.36 0.39 4323
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
warnings.warn(
Macro RMSE 1.17
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
Macro MAE 0.821
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
5.3 Logistic regression grid search
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
# Logistic regression grid search
warnings.warn(
evaluate_model(log_reg_grid_search.best_estimator_, ytest, Xtest) FutureWarning: `BaseEstimator._check_n_features` is deprecated
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484:
warnings.warn(
precision recall f1-score support
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
warnings.warn(
1 0.00 0.00 0.00 0
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
4
warnings.warn( 0.33 0.17 0.22 6
5 0.25 0.08 0.12 38
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
6
warnings.warn( 0.60 0.48 0.53 391
7 0.72 0.80 0.76 1842
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
8
warnings.warn( 0.61 0.61 0.61 1220
9 0.54 0.48 0.50 513
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
10
warnings.warn( 0.48 0.46 0.47 213
11 0.52 0.41 0.46 80
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: `BaseEstimator._check_feature_names` is deprecat
12
warnings.warn( 0.31 0.28 0.29 18
13 0.00 0.00 0.00 2
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
accuracy 0.64 4323
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
macro avg
warnings.warn( 0.40 0.34 0.36 4323
weighted avg 0.63 0.64 0.64 4323
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(
Macro RMSE 1.0
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:484: FutureWarning: `BaseEstimator._check_n_features` is deprecated
Macro MAE
warnings.warn( 0.752
/usr/local/lib/python3 10/dist packages/sklearn/base py:493: FutureWarning: `BaseEstimator check feature names` is deprecat
/usr/local/lib/python3.10/dist-packages/sklearn/base.py:493: FutureWarning: BaseEstimator._check_feature_names is deprecat
warnings.warn(
5.4 Random forest
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_tags.py:354: FutureWarning: The RandomOverSampler or classes from whi
warnings.warn(

You might also like