This article is a part of a 30 day Python challenge series. You can find the links to all the previous posts of this series here
- 30 Days of Python 👨💻 - Day One - Introduction
- 30 Days Of Python 👨💻 - Day 2 - Data Types I
- 30 Days of Python 👨💻 - Day 3 - Data Types II
- 30 Days Of Python 👨💻 - Day 4 - Data Types III
- 30 Days Of Python 👨💻 - Day 5 - Conditions And Loops I
- 30 Days Of Python 👨💻 - Day 6 - Loops II And Functions
- 30 Days Of Python 👨💻 - Day 7 - Developer Environment
- 30 Days Of Python 👨💻 - Day 8 - OOP Basics
- 30 Days Of Python 👨💻 - Day 9 - OOP Pillars
- 30 Days Of Python 👨💻 - Day 10 - OOP Missing Pieces
- 30 Days Of Python 👨💻 - Day 11 - Functional Programming
- 30 Days Of Python 👨💻 - Day 12 - Lambda Expression And Comprehensions
- 30 Days Of Python 👨💻 - Day 13 - Decorators
- 30 Days Of Python 👨💻 - Day 14 - Handling Errors
- 30 Days Of Python 👨💻 - Day 15 - Generators
- 30 Days Of Python 👨💻 - Day 16 - Module Basics
- 30 Days Of Python 👨💻 - Day 17 - External Modules
- 30 Days of Python 👨💻 - Day 18 - File I/O
- 30 Days Of Python 👨💻 - Day 19 - Regular Expressions
- 30 Days Of Python 👨💻 - Day 20 - Debugging And Testing
- 30 Days Of Python 👨💻 - Day 21 - Scripting Basics
- 30 Days of Python 👨💻 - Day 22 - Scripting Extras
- 30 Days Of Python 👨💻 - Day 23 - Web Scraping
- 30 Days Of Python 👨💻 - Day 24 - Web Development Basics
- 30 Days Of Python 👨💻 - Day 25 - Web Development Extras
- 30 Days of Python 👨💻 - Day 26 - Machine Learning Basics
- 30 Days Of Python 👨💻 - Day 27 - ML And Data Science
Today I explored the Scikit-Learn library and created a notebook project to go over some of the basics and try creating a machine learning model. Scikit-Learn is a vast library and it takes a lot of practice and exploration to get a grasp on it. I followed some tutorials and articles to try building a simple classifier model just to figure out how it works. It looked a bit intimidating to me but I decided to create a basic workflow in a Jupyter Notebook so that I can use it as a reference when I decide to dive deep into the ML and Data Science Domain.
Scikit-Learn is a popular Python library for Machine Learning. Scikit-Learn can process data provided to it and create machine learning models to learn patterns within the data and makes predictions using its tools.
Why Scikit-learn?
- Built on top of numpy and matplotlib libraries
- Has tons of built-in machine learning models
- Lot of methods to evaluate machine learning models
- Easy to understand and well-designed API
Usually, Machine Learning can be a bit overwhelming as it involves complex algorithms and statistics to analyze data. Scikit-learn abstracts this complexity and makes it easy to build models and train them without having to know much about mathematics and statistics.
Here is the Notebook I created today. The link to the Github repository is here.
Basics of the scikit-learn library
This notebook covers some of the basics of the amazing scikit-learn Python library. Some of the important use cases of the library have been listed in this notebook which can be used as a cheat-sheet for reference.
Some of the topics covered are:
- Getting the data ready
- Selecting the appropriate algorithm/estimator for the specific problem
- Fitting the model/algorithm to use it to make predictions on the data
- Evaluating a model
- Improving a model
- Saving a loading a trained model
Getting the data ready
The data used for this project will be the heart disease data set available from https://www.kaggle.com/ronitf/heart-disease-uci
- import pandas as pd
- import numpy as np
- heart_disease = pd.read_csv('data/heart.csv')
- heart_disease.head()
- <div class="table-wrapper">
- <table border="1" class="dataframe">
- <thead>
- <tr style="text-align: right;">
- <th></th>
- <th>age</th>
- <th>sex</th>
- <th>cp</th>
- <th>trestbps</th>
- <th>chol</th>
- <th>fbs</th>
- <th>restecg</th>
- <th>thalach</th>
- <th>exang</th>
- <th>oldpeak</th>
- <th>slope</th>
- <th>ca</th>
- <th>thal</th>
- <th>target</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <th>0</th>
- <td>63</td>
- <td>1</td>
- <td>3</td>
- <td>145</td>
- <td>233</td>
- <td>1</td>
- <td>0</td>
- <td>150</td>
- <td>0</td>
- <td>2.3</td>
- <td>0</td>
- <td>0</td>
- <td>1</td>
- <td>1</td>
- </tr>
- <tr>
- <th>1</th>
- <td>37</td>
- <td>1</td>
- <td>2</td>
- <td>130</td>
- <td>250</td>
- <td>0</td>
- <td>1</td>
- <td>187</td>
- <td>0</td>
- <td>3.5</td>
- <td>0</td>
- <td>0</td>
- <td>2</td>
- <td>1</td>
- </tr>
- <tr>
- <th>2</th>
- <td>41</td>
- <td>0</td>
- <td>1</td>
- <td>130</td>
- <td>204</td>
- <td>0</td>
- <td>0</td>
- <td>172</td>
- <td>0</td>
- <td>1.4</td>
- <td>2</td>
- <td>0</td>
- <td>2</td>
- <td>1</td>
- </tr>
- <tr>
- <th>3</th>
- <td>56</td>
- <td>1</td>
- <td>1</td>
- <td>120</td>
- <td>236</td>
- <td>0</td>
- <td>1</td>
- <td>178</td>
- <td>0</td>
- <td>0.8</td>
- <td>2</td>
- <td>0</td>
- <td>2</td>
- <td>1</td>
- </tr>
- <tr>
- <th>4</th>
- <td>57</td>
- <td>0</td>
- <td>0</td>
- <td>120</td>
- <td>354</td>
- <td>0</td>
- <td>1</td>
- <td>163</td>
- <td>1</td>
- <td>0.6</td>
- <td>2</td>
- <td>0</td>
- <td>2</td>
- <td>1</td>
- </tr>
- </tbody>
- </table>
- </div>

Join the conversation! Your thoughts help the community grow.