The post has been translated automatically. Original language: Russian
By now, you know:
— how to prepare data (numpy and pandas)
— how to visualize them (matplotlib and seaborn)
— how to build a baseline (scipy and sklearn)
— how to evaluate the result (e.g. learning curves)
— and how to present it (streamlit)
Let's move on: we'll gain experience in using it and learn more about machine learning algorithms. Let's start with simple tasks and basic families of algorithms.:
1️⃣ metric algorithms (example: kNN)
2️⃣ logical algorithms (example: decision tree)
3️⃣ Probabilistic algorithms (example: Naive Bayes)
You can hear about how they work a thousand times, but it's much more effective to conduct experiments yourself and visually see the difference.
Task #1. Dataset generation
To generate datasets, we suggest you familiarize yourself with the module:
import sklearn.datasets
API reference: sklearn.datasets
User Guide: Dataset loading utilities
Learn how to create and visualize the following datasets in 2D:
— make_circles (with or without noise)
— make_moons
— make_classification (a task with 3 classes)
— and upload UCI datasets using the load_iris example
Task #2. Visualization of the decisive rule

In order to draw what the decisive rule looks like in the two-dimensional case (and in the case of toy datasets, this is quite realistic), we suggest using DecisionBoundaryDisplay.:
from sklearn.inspection import DecisionBoundaryDisplay
advanced: for production datasets, you can solve the problem of dimensionality reduction.
The last three screenshots show visualizations of the decision rule of the kNN, DecisionTree, and Naive Bayes algorithms on the training and test subsamples of the toy dataset.



Task: Get similar visualizations.
The dataset can be reproduced using:
X, y = sklearn.datasets.make_classification(
n_features = 2, n_informative = 2,
n_classes = 3, n_redundant = 0,
n_clusters_per_class = 1,
random_state = 0
)
train_data, test_data, train_labels, test_labels = train_test_split(
X,
y,
test_size = 0.3,
random_state = 0
)
Useful information
Read first: Part 1 introduction to ML and ML libraries for Python
Previous issue: Part 7 presentation of results in ML
BigData Team: the way you learn best
К текущему моменту вы знаете:
— как подготовить данные (numpy и pandas)
— как их визуализировать (matplotlib и seaborn)
— как построить baseline (scipy и sklearn)
— как оценить результат (e.g. learning curves)
— и как его презентовать (streamlit)
Давайте двигаться дальше: получим опыт использования и более глубоко познаем алгоритмы машинного обучения. Начнем с простых задач и базовых семейств алгоритмов:
1️⃣ метрические алгоритмы (пример: kNN)
2️⃣ логические алгоритмы (пример: решающее дерево)
3️⃣ вероятностные алгоритмы (пример: Naive Bayes)
Можно тысячу раз услышать про то, как они работают, но гораздо эффективнее самостоятельно провести эксперименты и наглядно увидеть разницу.
Задача #1. Генерация датасетов
Для генерации датасетов, предлагаем познакомиться с модулем:
import sklearn.datasets
API reference: sklearn.datasets
User Guide: Dataset loading utilities
Научитесь создавать и визуализировать в 2D следующие датасеты:
— make_circles (с шумом и без)
— make_moons
— make_classification (задача с 3 классами)
— и загружать UCI датасеты на примере load_iris
Задача #2. Визуализация решающего правила

Для того, чтобы отрисовать как выглядит решающее правило в двумерном случае (а в случае игрушечных датасетов это вполне реалистично) предлагаем воспользоваться DecisionBoundaryDisplay:
from sklearn.inspection import DecisionBoundaryDisplay
advanced: для production датасетов можно решить задачу уменьшения размерности.
На последних трех скриншотах представлены визуализации решающего правила алгоритмов kNN, DecisionTree и Naive Bayes на тренировочной и тестовой подвыборках игрушечного датасета.



Задание: получите аналогичные визуализации.
Датасет можно воспроизвести с помощью:
X, y = sklearn.datasets.make_classification(
n_features = 2, n_informative = 2,
n_classes = 3, n_redundant = 0,
n_clusters_per_class = 1,
random_state = 0
)
train_data, test_data, train_labels, test_labels = train_test_split(
X,
y,
test_size = 0.3,
random_state = 0
)
Полезная информация
Читать сначала: ч.1 введение в ML и библиотеки ML для Python
Предыдущий выпуск: ч.7 презентация результатов в ML
BigData Team: the way you learn best