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

Contenido del Curso

Classification with Python

Classification with Python

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

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.

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 the sklearn.

Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 4
toggle bottom row

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.

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 the sklearn.

Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 4
toggle bottom row

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.

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 the sklearn.

Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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.

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 the sklearn.

Your task is to build a Decision Tree and find the best max_depth and min_samples_leaf using grid search.

Tarea

  1. Import the DecisionTreeClassifier class from sklearn.tree.
  2. Assign an instance of DecisionTreeClassifier to the decision_tree variable.
  3. Create a dictionary for a GridSearchCV to run through [1, 2, 3, 4, 5, 6, 7] values of max_depth and [1, 2, 4, 6] values of min_samples_leaf.
  4. Create a GridSearchCV object and train it.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 4
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt