Challenge: Implementing a Decision Tree
In this challenge, you will use the Titanic dataset, which contains information about passengers on the Titanic, including their age, sex, family size, and more. The goal is to predict whether a passenger survived or not.
1234import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b71ff7ac-3932-41d2-a4d8-060e24b00129/titanic.csv') print(df.head())
To implement the Decision Tree, you can use the DecisionTreeClassifier from sklearn:
Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.
Swipe to start coding
You are given a Titanic dataset stored as a DataFrame in the df variable.
- Initialize a Decision Tree model and store it in the
decision_treevariable. - Create a dictionary for
GridSearchCVto iterate through[1, 2, 3, 4, 5, 6, 7]values formax_depthand[1, 2, 4, 6]values formin_samples_leaf, and store it in theparam_gridvariable. - Initialize and train a
GridSearchCVobject, set the number of folds to10, and store the trained model in thegrid_cvvariable.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 5.88
Challenge: Implementing a Decision Tree
Swipe um das Menü anzuzeigen
In this challenge, you will use the Titanic dataset, which contains information about passengers on the Titanic, including their age, sex, family size, and more. The goal is to predict whether a passenger survived or not.
1234import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b71ff7ac-3932-41d2-a4d8-060e24b00129/titanic.csv') print(df.head())
To implement the Decision Tree, you can use the DecisionTreeClassifier from sklearn:
Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.
Swipe to start coding
You are given a Titanic dataset stored as a DataFrame in the df variable.
- Initialize a Decision Tree model and store it in the
decision_treevariable. - Create a dictionary for
GridSearchCVto iterate through[1, 2, 3, 4, 5, 6, 7]values formax_depthand[1, 2, 4, 6]values formin_samples_leaf, and store it in theparam_gridvariable. - Initialize and train a
GridSearchCVobject, set the number of folds to10, and store the trained model in thegrid_cvvariable.
Lösung
Danke für Ihr Feedback!
single