Question: import pandas as pd import numpy as np import os import matplotlib.pyplot as plt import seaborn as sns from sklearn.tree import DecisionTreeClassifier from sklearn.model _
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.tree import DecisionTreeClassifier
from sklearn.modelselection import traintestsplit
from sklearn.metrics import accuracyscore
from sklearn.modelselection import GridSearchCV
filename ospath.joinosgetcwd "data", "cellcelltrain.csv
df pdreadcsvfilename header
y dfChurn
X dfdropcolumns 'Churn', axis
Xhead
Xtrain, Xtest, ytrain, ytest traintestsplitX y testsize randomstate
md n for n in range
msl n for n in range
paramgridmaxdepth':md 'minsamplesleaf':msl
paramgrid
printRunning Grid Search...
# Create a DecisionTreeClassifier model object without supplying arguments
model DecisionTreeClassifier
# Run a Grid Search with fold crossvalidation using our the model.
# Pass all relevant parameters to GridSearchCV and assign the output to the object 'grid'
grid GridSearchCVmodel paramgrid, cv
# Fit the model to the training data and assign the fitted model to the
# variable gridsearch
gridsearch grid.fitXtrain, ytrain
printDone
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
