Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Implementing a Decision Tree | Decision Tree
Classification with Python
course content

Cursusinhoud

Classification with Python

Classification with Python

1. k-NN Classifier
2. Logistic Regression
3. Decision Tree
4. Random Forest
5. Comparing Models

book
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.

1234
import 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())
copy

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.

Taak

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_tree variable.
  • Create a dictionary for GridSearchCV to iterate through [1, 2, 3, 4, 5, 6, 7] values for max_depth and [1, 2, 4, 6] values for min_samples_leaf, and store it in the param_grid variable.
  • Initialize and train a GridSearchCV object, set the number of folds to 10, and store the trained model in the grid_cv variable.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 4
toggle bottom row

book
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.

1234
import 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())
copy

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.

Taak

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_tree variable.
  • Create a dictionary for GridSearchCV to iterate through [1, 2, 3, 4, 5, 6, 7] values for max_depth and [1, 2, 4, 6] values for min_samples_leaf, and store it in the param_grid variable.
  • Initialize and train a GridSearchCV object, set the number of folds to 10, and store the trained model in the grid_cv variable.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 4
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt