python-machine-learning-book-3rd-edition
The "Python Machine Learning (3rd edition)" book code repository
Top Related Projects
Notebooks and code for the book "Introduction to Machine Learning with Python"
A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Python Data Science Handbook: full text in Jupyter Notebooks
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
The fastai book, published as Jupyter Notebooks
An Open Source Machine Learning Framework for Everyone
Quick Overview
The "python-machine-learning-book-3rd-edition" repository contains code examples and resources for the book "Python Machine Learning" by Sebastian Raschka and Vahid Mirjalili. It covers various machine learning and deep learning topics, providing practical implementations and explanations for readers to follow along with the book's content.
Pros
- Comprehensive coverage of machine learning concepts and techniques
- Well-organized code examples that correspond to book chapters
- Includes Jupyter notebooks for interactive learning
- Regularly updated to maintain compatibility with latest libraries
Cons
- Requires the accompanying book for full context and explanations
- Some advanced topics may be challenging for beginners
- Large repository size due to numerous examples and datasets
Code Examples
- Loading and preprocessing data:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# Load the data
df = pd.read_csv('data.csv')
# Split the data
X = df.drop('target', axis=1)
y = df['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Scale the features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
- Training a simple neural network:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential([
Dense(64, activation='relu', input_shape=(X_train.shape[1],)),
Dense(32, activation='relu'),
Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(X_train_scaled, y_train, epochs=10, batch_size=32, validation_split=0.2)
- Evaluating model performance:
from sklearn.metrics import accuracy_score, classification_report
y_pred = model.predict(X_test_scaled)
y_pred_classes = (y_pred > 0.5).astype(int)
accuracy = accuracy_score(y_test, y_pred_classes)
print(f"Accuracy: {accuracy:.2f}")
print(classification_report(y_test, y_pred_classes))
Getting Started
To get started with the examples in this repository:
-
Clone the repository:
git clone https://github.com/rasbt/python-machine-learning-book-3rd-edition.git
-
Install the required dependencies:
pip install -r requirements.txt
-
Navigate to the desired chapter's directory and open the Jupyter notebooks:
cd python-machine-learning-book-3rd-edition/ch02 jupyter notebook
-
Follow along with the book and experiment with the provided code examples.
Competitor Comparisons
Notebooks and code for the book "Introduction to Machine Learning with Python"
Pros of introduction_to_ml_with_python
- More beginner-friendly approach with a focus on practical applications
- Covers a wider range of ML topics, including unsupervised learning and text processing
- Includes more visualizations and explanatory diagrams
Cons of introduction_to_ml_with_python
- Less in-depth coverage of advanced topics like deep learning
- Fewer exercises and coding challenges for readers
- Less frequent updates compared to python-machine-learning-book-3rd-edition
Code Comparison
introduction_to_ml_with_python:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, random_state=0)
knn = KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)
python-machine-learning-book-3rd-edition:
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1, stratify=y)
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)
X_test_std = sc.transform(X_test)
Both repositories provide excellent resources for learning machine learning with Python. introduction_to_ml_with_python is more suitable for beginners, while python-machine-learning-book-3rd-edition offers a more comprehensive and advanced coverage of ML topics.
A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Pros of handson-ml2
- More comprehensive coverage of deep learning topics
- Includes practical exercises and hands-on projects
- Regularly updated with new content and examples
Cons of handson-ml2
- Less focus on traditional machine learning algorithms
- May be overwhelming for absolute beginners
Code Comparison
handson-ml2:
from sklearn.ensemble import RandomForestClassifier
forest_clf = RandomForestClassifier(n_estimators=100, random_state=42)
forest_clf.fit(X_train, y_train)
y_pred = forest_clf.predict(X_test)
python-machine-learning-book-3rd-edition:
from sklearn.ensemble import RandomForestClassifier
forest = RandomForestClassifier(n_estimators=25,
random_state=1,
n_jobs=2)
forest.fit(X_train, y_train)
Both repositories provide excellent resources for learning machine learning with Python. handson-ml2 offers a more in-depth exploration of deep learning and practical projects, making it suitable for those interested in advanced topics. However, it may be less accessible for beginners. python-machine-learning-book-3rd-edition provides a more balanced coverage of traditional machine learning algorithms and may be more suitable for those new to the field. The code examples in both repositories are similar, with minor differences in parameter settings and variable naming conventions.
Python Data Science Handbook: full text in Jupyter Notebooks
Pros of PythonDataScienceHandbook
- Broader coverage of data science topics, including data manipulation and visualization
- More interactive Jupyter notebooks for hands-on learning
- Extensive use of popular libraries like NumPy, Pandas, and Matplotlib
Cons of PythonDataScienceHandbook
- Less focus on advanced machine learning algorithms and techniques
- Older content, last updated in 2018
- Fewer practical examples of real-world machine learning applications
Code Comparison
PythonDataScienceHandbook:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('data.csv')
plt.scatter(data['x'], data['y'])
plt.show()
python-machine-learning-book-3rd-edition:
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)
The PythonDataScienceHandbook focuses more on data manipulation and visualization, while python-machine-learning-book-3rd-edition emphasizes machine learning algorithms and scikit-learn usage. Both repositories offer valuable resources for learning data science and machine learning, with PythonDataScienceHandbook providing a broader introduction and python-machine-learning-book-3rd-edition offering more depth in machine learning techniques.
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
Pros of ML-For-Beginners
- More comprehensive curriculum covering various ML topics
- Includes hands-on projects and quizzes for practical learning
- Designed for beginners with a focus on accessibility
Cons of ML-For-Beginners
- Less in-depth coverage of advanced ML concepts
- Primarily uses Scikit-learn, limiting exposure to other libraries
- May not be as suitable for experienced practitioners
Code Comparison
ML-For-Beginners:
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)
Python-Machine-Learning-Book-3rd-Edition:
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1, stratify=y)
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)
X_test_std = sc.transform(X_test)
lr = LogisticRegression(random_state=1)
lr.fit(X_train_std, y_train)
The code examples show that ML-For-Beginners focuses on simpler implementations, while Python-Machine-Learning-Book-3rd-Edition includes more advanced preprocessing and model creation techniques.
The fastai book, published as Jupyter Notebooks
Pros of fastbook
- Focuses on practical, state-of-the-art deep learning techniques
- Utilizes the fastai library, which simplifies complex deep learning tasks
- Includes more recent topics like transfer learning and GANs
Cons of fastbook
- May be less accessible for beginners due to its advanced content
- Covers fewer traditional machine learning algorithms
- Primarily uses PyTorch, which may not be ideal for those preferring TensorFlow
Code Comparison
fastbook:
from fastai.vision.all import *
path = untar_data(URLs.PETS)/'images'
def is_cat(x): return x[0].isupper()
dls = ImageDataLoaders.from_name_func(
path, get_image_files(path), valid_pct=0.2, seed=42,
label_func=is_cat, item_tfms=Resize(224))
python-machine-learning-book-3rd-edition:
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=1, stratify=y)
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)
X_test_std = sc.transform(X_test)
An Open Source Machine Learning Framework for Everyone
Pros of TensorFlow
- Comprehensive ecosystem with tools for deployment, visualization, and distributed training
- Supports multiple programming languages beyond Python
- Highly scalable for large-scale machine learning projects
Cons of TensorFlow
- Steeper learning curve for beginners
- Can be more complex to set up and configure
- Less focus on traditional machine learning algorithms
Code Comparison
Python-Machine-Learning-Book-3rd-Edition:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1, stratify=y)
TensorFlow:
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
Python-Machine-Learning-Book-3rd-Edition is more focused on teaching machine learning concepts with practical examples, while TensorFlow is a powerful library for building and deploying machine learning models at scale. The book repository provides a comprehensive guide to various ML algorithms and techniques, making it ideal for learners. TensorFlow, on the other hand, offers a robust framework for deep learning and complex model architectures, suitable for advanced projects and production environments.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Python Machine Learning (3rd Ed.) Code Repository
Code repositories for the 1st and 2nd edition are available at
- https://github.com/rasbt/python-machine-learning-book and
- https://github.com/rasbt/python-machine-learning-book-2nd-edition
Python Machine Learning, 3rd Ed.
to be published December 12th, 2019
Paperback: 770 pages
Publisher: Packt Publishing
Language: English
ISBN-10: 1789955750
ISBN-13: 978-1789955750
Kindle ASIN: B07VBLX2W7
Links
Table of Contents and Code Notebooks
Helpful installation and setup instructions can be found in the README.md file of Chapter 1
Please note that these are just the code examples accompanying the book, which we uploaded for your convenience; be aware that these notebooks may not be useful without the formulae and descriptive text.
- Machine Learning - Giving Computers the Ability to Learn from Data [open dir]
- Training Machine Learning Algorithms for Classification [open dir]
- A Tour of Machine Learning Classifiers Using Scikit-Learn [open dir]
- Building Good Training Sets â Data Pre-Processing [open dir]
- Compressing Data via Dimensionality Reduction [open dir]
- Learning Best Practices for Model Evaluation and Hyperparameter Optimization [open dir]
- Combining Different Models for Ensemble Learning [open dir]
- Applying Machine Learning to Sentiment Analysis [open dir]
- Embedding a Machine Learning Model into a Web Application [open dir]
- Predicting Continuous Target Variables with Regression Analysis [open dir]
- Working with Unlabeled Data â Clustering Analysis [open dir]
- Implementing a Multi-layer Artificial Neural Network from Scratch [open dir]
- Parallelizing Neural Network Training with TensorFlow [open dir]
- Going Deeper: The Mechanics of TensorFlow [open dir]
- Classifying Images with Deep Convolutional Neural Networks [open dir]
- Modeling Sequential Data Using Recurrent Neural Networks [open dir]
- Generative Adversarial Networks for Synthesizing New Data [open dir]
- Reinforcement Learning for Decision Making in Complex Environments [open dir]
Raschka, Sebastian, and Vahid Mirjalili. Python Machine Learning, 3rd Ed. Packt Publishing, 2019.
@book{RaschkaMirjalili2019,
address = {Birmingham, UK},
author = {Raschka, Sebastian and Mirjalili, Vahid},
edition = {3},
isbn = {978-1789955750},
publisher = {Packt Publishing},
title = {{Python Machine Learning, 3rd Ed.}},
year = {2019}
}
Top Related Projects
Notebooks and code for the book "Introduction to Machine Learning with Python"
A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Python Data Science Handbook: full text in Jupyter Notebooks
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
The fastai book, published as Jupyter Notebooks
An Open Source Machine Learning Framework for Everyone
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot