machine-learning-book
Code Repository for Machine Learning with PyTorch and Scikit-Learn
Top Related Projects
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.
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.
A curated list of awesome Machine Learning frameworks, libraries and software.
scikit-learn: machine learning in Python
Quick Overview
The "machine-learning-book" repository by Sebastian Raschka contains code examples and resources for the book "Machine Learning with PyTorch and Scikit-Learn." It covers a wide range of machine learning topics, from basic concepts to advanced techniques, with practical implementations using popular Python libraries.
Pros
- Comprehensive coverage of machine learning topics
- Practical code examples using PyTorch and Scikit-Learn
- Regular updates and maintenance by the author
- Supplementary materials like datasets and Jupyter notebooks
Cons
- Primarily focused on PyTorch and Scikit-Learn, may not cover other ML frameworks extensively
- Requires basic knowledge of Python and machine learning concepts
- Some advanced topics may be challenging for beginners
- Limited coverage of deep learning architectures compared to traditional ML algorithms
Code Examples
- Loading and preprocessing data using Scikit-Learn:
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
- Training a simple neural network using PyTorch:
import torch
import torch.nn as nn
class SimpleNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super().__init__()
self.fc1 = nn.Linear(input_size, hidden_size)
self.fc2 = nn.Linear(hidden_size, output_size)
self.relu = nn.ReLU()
def forward(self, x):
x = self.relu(self.fc1(x))
x = self.fc2(x)
return x
model = SimpleNN(4, 10, 3)
- Evaluating a model using Scikit-Learn:
from sklearn.metrics import accuracy_score, classification_report
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
report = classification_report(y_test, y_pred)
print(f"Accuracy: {accuracy}")
print(report)
Getting Started
To get started with the code examples in this repository:
-
Clone the repository:
git clone https://github.com/rasbt/machine-learning-book.git
-
Install the required dependencies:
pip install -r requirements.txt
-
Navigate to the desired chapter directory and run the Jupyter notebooks or Python scripts:
cd machine-learning-book/ch02 jupyter notebook
Competitor Comparisons
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-ml3
- More comprehensive coverage of deep learning topics
- Includes practical exercises and hands-on examples
- Regularly updated with the latest ML/DL advancements
Cons of handson-ml3
- Less focus on traditional machine learning algorithms
- May be overwhelming for absolute beginners in the field
Code Comparison
handson-ml3:
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
machine-learning-book:
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train)
The code snippets highlight the different focus areas of the repositories. handson-ml3 emphasizes deep learning with TensorFlow, while machine-learning-book concentrates on traditional ML algorithms using scikit-learn.
Both repositories offer valuable resources for learning machine learning, but they cater to slightly different audiences and learning objectives. handson-ml3 is more suitable for those interested in deep learning and neural networks, while machine-learning-book provides a solid foundation in classical machine learning techniques.
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)
Pros of TensorFlow-Examples
- Focused specifically on TensorFlow, providing in-depth examples
- Includes a wide range of practical, ready-to-run code examples
- Regularly updated to keep pace with TensorFlow's evolving ecosystem
Cons of TensorFlow-Examples
- Limited theoretical explanations compared to Machine-Learning-Book
- Narrower scope, focusing primarily on TensorFlow rather than broader ML concepts
- May be less suitable for beginners without prior ML knowledge
Code Comparison
TensorFlow-Examples:
import tensorflow as tf
# Create a constant tensor
hello = tf.constant('Hello, TensorFlow!')
# Start a TensorFlow session
sess = tf.Session()
# Run the op
print(sess.run(hello))
Machine-Learning-Book:
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)
X_test_std = sc.transform(X_test)
This comparison highlights TensorFlow-Examples' focus on TensorFlow-specific code, while Machine-Learning-Book provides a broader perspective using various libraries and techniques.
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
Pros of ML-For-Beginners
- More comprehensive curriculum structure with 12 weeks of content
- Includes practical projects and quizzes for hands-on learning
- Covers a wider range of ML topics, including NLP and computer vision
Cons of ML-For-Beginners
- Less in-depth coverage of mathematical foundations
- Fewer code examples and implementations of algorithms
- Limited focus on advanced ML techniques and research-oriented topics
Code Comparison
ML-For-Beginners:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
machine-learning-book:
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)
Both repositories use scikit-learn for data splitting, but machine-learning-book includes stratification and a different test size.
ML-For-Beginners is more suitable for beginners and those seeking a structured learning path with practical projects. machine-learning-book is better for readers interested in a deeper understanding of ML algorithms and their implementation details.
Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.
Pros of ML-From-Scratch
- Focuses on implementing algorithms from scratch, providing a deeper understanding of the inner workings
- Covers a wide range of machine learning algorithms and techniques
- Code is well-organized and easy to follow, with clear comments and explanations
Cons of ML-From-Scratch
- Less comprehensive theoretical explanations compared to machine-learning-book
- May not be as suitable for beginners who need more guidance and context
- Lacks the extensive examples and case studies found in machine-learning-book
Code Comparison
ML-From-Scratch:
class LinearRegression(Regression):
def fit(self, X, y):
X = np.insert(X, 0, 1, axis=1)
U, S, V = np.linalg.svd(X.T.dot(X))
S = np.diag(S)
self.w = V.dot(np.linalg.pinv(S)).dot(U.T).dot(X.T).dot(y)
machine-learning-book:
class LinearRegression:
def fit(self, X, y):
X = np.column_stack((np.ones(len(X)), X))
self.w_ = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)
return self
Both implementations showcase linear regression, but ML-From-Scratch uses SVD for improved numerical stability, while machine-learning-book uses a simpler approach with matrix inversion.
A curated list of awesome Machine Learning frameworks, libraries and software.
Pros of awesome-machine-learning
- Comprehensive collection of ML resources across various languages and platforms
- Regularly updated with community contributions
- Includes links to datasets, books, and courses
Cons of awesome-machine-learning
- Less structured learning path compared to machine-learning-book
- May overwhelm beginners with the sheer volume of resources
- Lacks in-depth explanations or tutorials
Code comparison
machine-learning-book:
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=0)
awesome-machine-learning: No specific code examples are provided in the repository. It primarily consists of links and resources.
Summary
machine-learning-book is a structured learning resource with code examples and explanations, ideal for those seeking a guided approach to machine learning. awesome-machine-learning, on the other hand, is a vast collection of resources that serves as a comprehensive reference for ML practitioners at all levels. While machine-learning-book offers a more focused learning experience, awesome-machine-learning provides a broader overview of the field with links to various tools, libraries, and learning materials.
scikit-learn: machine learning in Python
Pros of scikit-learn
- Comprehensive library with a wide range of machine learning algorithms and tools
- Well-established, extensively documented, and widely used in industry and research
- Actively maintained with regular updates and improvements
Cons of scikit-learn
- Steeper learning curve for beginners due to its extensive functionality
- Less focused on educational content and explanations compared to machine-learning-book
Code Comparison
machine-learning-book:
from mlxtend.plotting import plot_decision_regions
import matplotlib.pyplot as plt
plot_decision_regions(X, y, clf=model)
plt.title('Decision Boundary')
plt.show()
scikit-learn:
from sklearn.svm import SVC
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)
model = SVC(kernel='rbf', C=1.0)
model.fit(X_train, y_train)
Summary
scikit-learn is a powerful, production-ready machine learning library with extensive functionality, while machine-learning-book focuses more on educational content and explanations. scikit-learn offers a wider range of algorithms and tools but may be more challenging for beginners. machine-learning-book provides more accessible learning resources but has a narrower scope in terms of implemented algorithms and features.
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
Machine Learning with PyTorch and Scikit-Learn Book
Code Repository
Paperback: 770 pages
Publisher: Packt Publishing
Language: English
ISBN-10: 1801819319
ISBN-13: 978-1801819312
Kindle ASIN: B09NW48MR1
Links
Table of Contents and Code Notebooks
Helpful installation and setup instructions can be found in the README.md file of Chapter 1.
In addition, Zbynek Bazanowski contributed this helpful guide explaining how to run the code examples on Google Colab.
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]
- 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 PyTorch [open dir]
- Going Deeper -- The Mechanics of PyTorch [open dir]
- Classifying Images with Deep Convolutional Neural Networks [open dir]
- Modeling Sequential Data Using Recurrent Neural Networks [open dir]
- Transformers -- Improving Natural Language Processing with Attention Mechanisms [open dir]
- Generative Adversarial Networks for Synthesizing New Data [open dir]
- Graph Neural Networks for Capturing Dependencies in Graph Structured Data [open dir]
- Reinforcement Learning for Decision Making in Complex Environments [open dir]
Sebastian Raschka, Yuxi (Hayden) Liu, and Vahid Mirjalili. Machine Learning with PyTorch and Scikit-Learn. Packt Publishing, 2022.
@book{mlbook2022,
address = {Birmingham, UK},
author = {Sebastian Raschka, and Yuxi (Hayden) Liu, and Vahid Mirjalili},
isbn = {978-1801819312},
publisher = {Packt Publishing},
title = {{Machine Learning with PyTorch and Scikit-Learn}},
year = {2022}
}
â
Coding Environment
Please see the ch01/README.md file for setup recommendations.
Translations into other Languages
- Serbian Translation: MaÅ¡insko uÄenje uz PyTorch i Scikit-Learn. ISBN: 9788673105772
Top Related Projects
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.
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)
12 weeks, 26 lessons, 52 quizzes, classic Machine Learning for all
Machine Learning From Scratch. Bare bones NumPy implementations of machine learning models and algorithms with a focus on accessibility. Aims to cover everything from linear regression to deep learning.
A curated list of awesome Machine Learning frameworks, libraries and software.
scikit-learn: machine learning in Python
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