Challenge: Implementing a Decision Tree
In this challenge, you will use the titanic dataset. It holds information about passengers on the Titanic, including their age, sex, family size, etc. And the task is to predict whether a person 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 the 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
- Import the
DecisionTreeClassifierclass fromsklearn.tree. - Assign an instance of
DecisionTreeClassifierto thedecision_treevariable. - Create a dictionary for a
GridSearchCVto run through[1, 2, 3, 4, 5, 6, 7]values ofmax_depthand[1, 2, 4, 6]values ofmin_samples_leaf. - Create a
GridSearchCVobject and train it.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Oppsummer dette kapittelet
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 3.57
Challenge: Implementing a Decision Tree
Sveip for å vise menyen
In this challenge, you will use the titanic dataset. It holds information about passengers on the Titanic, including their age, sex, family size, etc. And the task is to predict whether a person 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 the 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
- Import the
DecisionTreeClassifierclass fromsklearn.tree. - Assign an instance of
DecisionTreeClassifierto thedecision_treevariable. - Create a dictionary for a
GridSearchCVto run through[1, 2, 3, 4, 5, 6, 7]values ofmax_depthand[1, 2, 4, 6]values ofmin_samples_leaf. - Create a
GridSearchCVobject and train it.
Løsning
Takk for tilbakemeldingene dine!
single