Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sample hyperparameter tuning with grid search cv

# Define params_dt
params_dt = {
             'max_depth': [2, 3, 4],
             'min_samples_leaf': [0.12, 0.14, 0.16, 0.18]
            }
# Import GridSearchCV
from sklearn.model_selection import GridSearchCV

# Instantiate grid_dt
grid_dt = GridSearchCV(estimator=...base_model...,
                       param_grid=params_dt,
                       scoring='roc_auc',
                       cv=5,
                       n_jobs=-1)

#Train the model
grid_dt.fit(X_train, y_train)

# Import roc_auc_score from sklearn.metrics 
from sklearn.metrics import roc_auc_score

# Extract the best estimator
best_model = grid_dt.best_estimator_

# Predict the test set probabilities of the positive class
y_pred_proba = best_model.predict_proba(X_test)[:,1]

# Compute test_roc_auc
test_roc_auc = roc_auc_score(y_test, y_pred_proba)

# Print test_roc_auc
print('Test set ROC AUC score: {:.3f}'.format(test_roc_auc))
Comment

PREVIOUS NEXT
Code Example
Python :: class decorator python 
Python :: sort list in python 
Python :: polymorphism in python 
Python :: add element to list 
Python :: Python NumPy expand_dims Function Example 
Python :: removing stop words from the text 
Python :: request foucus tkinter widget 
Python :: django create multiple objects 
Python :: How to find the maximum subarray sum in python? 
Python :: python basic data types 
Python :: python list comprehensions 
Python :: list all files in a folder 
Python :: python interview questions and answers pdf 
Python :: Python NumPy delete Function Example Deletion from 1D array 
Python :: getting current user in django 
Python :: what is serializer in django 
Python :: how to add element to list python 
Python :: gamma distribution python normalized 
Python :: python calling method from constructor 
Python :: python convert np datetime to string 
Python :: how to get the length of a string in python stack overflow 
Python :: try except in list comprehension 
Python :: How To Remove Elements From a Set using remove() function in python 
Python :: all string methods in python 
Python :: how to write something in python 
Python :: return more than one value python 
Python :: matrix multiplication python without numpy 
Python :: search method in python 
Python :: np.divide 
Python :: python csv to excel 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =