🔹 Why Python for Data Science & Machine Learning?
Python is widely used ("lingua franca") in data science.
It combines:
o the power of general-purpose programming languages
o the simplicity of scientific scripting languages like MATLAB or R.
It has large collections of libraries for:
o data loading
o visualization
o statistics
o natural language processing
o image processing
o and much more.
This gives data scientists access to many tools for both general and specialized tasks.
Python allows direct interaction with code using:
o terminals
o Jupyter Notebook
Machine learning and data analysis require fast, repeated experimentation — Python
supports this interactive and iterative process.
Python can also:
o create complex GUIs
o build web services
o integrate with existing systems.
🔹 What is scikit-learn?
✅ What is scikit-learn?
scikit-learn is a free, open-source Python library for machine learning.
It helps us:
train machine learning models
test models
evaluate accuracy
make predictions
use ready-made ML algorithms
It includes:
Classification (e.g., spam-vs-not spam)
Regression (predicting numbers like house price)
Clustering (grouping data)
Dimensionality reduction
Model selection & evaluation
scikit-learn is open-source — free to use and distribute.
It contains many modern machine learning algorithms.
Most widely used Python ML library — popular in industry
Many tutorials and code examples are available online.
Works smoothly with other scientific Python tools.
🔹 Documentation
While learning, it's recommended to also consult the:
o scikit-learn User Guide
o API documentation
The online documentation is very detailed and useful.
🔹 Installing scikit-learn – Required Packages
scikit-learn needs:
NumPy
SciPy
For plotting and interactive coding, also install:
matplotlib
IPython
Jupyter Notebook
🔹 Recommended Python Distributions
Anaconda
Designed for data processing, predictive analytics, and scientific computing.
Includes NumPy, SciPy, matplotlib, pandas, IPython, Jupyter Notebook, scikit-learn.
Works on MacOS, Windows, and Linux.
Includes Intel MKL — improves speed automatically.
Recommended for beginners.
Enthought Canopy
Scientific Python distribution.
Comes with NumPy, SciPy, matplotlib, pandas, IPython.
Free version does not include scikit-learn.
Academic users can request a license for full access.
Works on MacOS, Windows, and Linux for Python 2.7.x.
Python(x,y)
Scientific Python distribution specifically for Windows.
Includes NumPy, SciPy, matplotlib, pandas, IPython, and scikit-learn.
🔹 Installing with pip (if Python is already installed)
pip install numpy scipy matplotlib ipython scikit-learn pandas
Essential Libraries and Tools
🧪 Jupyter Notebook
A browser-based environment to run Python code interactively.
Great for exploratory data analysis.
Supports many languages, but we use it mainly for Python.
You can mix code, text, and images in the same document.
🔢 NumPy
A core Python package for scientific computing.
Provides:
o multidimensional arrays
o linear algebra
o Fourier transform
o random number generation
In scikit-learn, data is handled as NumPy arrays.
NumPy arrays have:
o only one data type per array
o fast computational performance
The main structure is the ndarray class.
Example:
[[1 2 3]
[4 5 6]]
🧠 SciPy
A library of scientific computation functions in Python.
Includes:
o advanced linear algebra
o optimization
o special mathematical functions
o signal processing
o statistical distributions
scikit-learn uses SciPy internally.
Most important part for us: [Link]
Used for sparse matrices:
o they store only non-zero values
o useful when data is mostly zeros
Example: identity matrix stored sparsely
📊 matplotlib
Major plotting library in Python.
Used for visualizing:
o line graphs
o histograms
o scatter plots, etc.
In Jupyter Notebook, we activate plotting using:
o %matplotlib notebook (interactive mode)
o %matplotlib inline (static mode)
Example: plotting y = sin(x) as a line chart.
🧾 pandas
Library for data analysis and data manipulation.
Main object: DataFrame — like an Excel sheet.
Each column can hold different data types:
o integers
o floats
o strings
o dates
Supports SQL-like table queries.
Can read data from many formats:
o CSV
o Excel
o SQL databases
Example: DataFrame of people with Name, Age, and Location.
You can query data — e.g., select rows where Age > 30.
🧩 mglearn
A helper library that comes with the book.
Contains:
o utility functions for plotting
o easy access to sample datasets
Used mainly to simplify code and make nicer graphs.
Not essential to learn in depth — it’s mainly convenience.