Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← Back to Projects

Decision Tree Project Tutorial

Difficulty

  • easy

Average duration

2 hrs

Technologies

Difficulty

  • easy

Average duration

2 hrs

Technologies

  • Understand a new dataset.
  • Process it by applying exploratory data analysis (EDA).
  • Model the data building a decision tree.
  • Analyze the results and optimize the model.

🌱 How to start this project

Follow the instructions below:

  1. Create a new repository based on machine learning project by clicking here.
  2. Open the newly created repository in Codespace using the Codespace button extension.
  3. Once the Codespace VSCode has finished opening, start your project by following the instructions below.

πŸš› How to deliver this project

Once you have finished solving the exercises, be sure to commit your changes, push them to your repository, and go to 4Geeks.com to upload the repository link.

πŸ“ Instructions

Predicting Diabetes

This dataset originally comes from the National Institute of Diabetes and Digestive and Kidney Diseases. The goal is to predict, based on diagnostic measures, whether or not a patient has diabetes.

Step 1: Loading the dataset

The dataset can be found in this project folder under the name diabetes.csv. You can load it into the code directly from the link:

1https://raw.githubusercontent.com/4GeeksAcademy/decision-tree-project-tutorial/main/diabetes.csv

Or download it and add it by hand in your repository. In this dataset, you will find the following variables:

  • Pregnancies. Number of pregnancies of the patient (numeric)
  • Glucose. Plasma glucose concentration 2 hours after an oral glucose tolerance test (numeric)
  • BloodPressure. Diastolic blood pressure (measured in mm Hg) (numeric)
  • SkinThickness. Triceps skin fold thickness (measured in mm) (numeric)
  • Insulin. 2-hour serum insulin (measured in mu U/ml) (numeric)
  • BMI. Body mass index (numeric)
  • DiabetesPedigreeFunction. Diabetes Pedigree Function (numeric)
  • Age. Age of patient (numeric)
  • Outcome. Class variable (0 or 1), being 0 negative in diabetes and 1 positive (numeric)

Step 2: Perform a full EDA

This second step is vital to ensure that we keep the variables that are strictly necessary and eliminate those that are not relevant or do not provide information. Use the example Notebook we worked on and adapt it to this use case.

Be sure to conveniently divide the data set into train and test as we have seen in previous lessons.

Step 3: Build a decision tree

Start solving the problem by implementing a decision tree and analyze which of the two types satisfies your needs. Train it and analyze its results. Try modifying the function for calculating the purity of the nodes and use all the available ones. Describe them and analyze your results by graphing them.

Step 4: Optimize the previous model

After training the tree with the different purity functions, it selects the best of them and optimizes its hyperparameters using a grid search.

Step 5: Save the model

Store the model in the corresponding folder.

Note: We also incorporated the solution samples on ./solution.ipynb that we strongly suggest you only use if you are stuck for more than 30 min or if you have already finished and want to compare it with your approach.

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

2 hrs

Technologies

Difficulty

  • easy

Average duration

2 hrs

Technologies

Difficulty

  • easy

Average duration

2 hrs

Technologies

Difficulty

  • easy

Average duration

2 hrs

Technologies

Sign up and get access to solution files and videos

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

2 hrs

Technologies

Difficulty

  • easy

Average duration

2 hrs

Technologies