liveBook · Manning

Scikit-learn

As explained in Grokking Machine Learning

An open-source Python library providing classical machine-learning algorithms and utilities.

Scikit-learn is a Python package for training, testing, and evaluating classical machine-learning models. It turns prepared features and labels into fitted models, including decision trees and support vector machines. section 9.4 section 13.7

A typical workflow uses Scikit-learn to:

  • Fit a decision tree to feature columns and labels. section 9.4
  • Train a linear SVM and adjust its C parameter to balance margin width against classification mistakes. section 11.2
  • Prepare numerical features, encode categorical features, select useful inputs, and compare hyperparameters with grid search and k-fold cross-validation. section 13.7

A small decision-tree experiment

Put two features, x_0 and x_1, in a DataFrame, store class labels in y, then fit DecisionTreeClassifier(). The resulting depth-two tree creates rectangular regions using thresholds such as x_0 = 5 and x_1 = 8 or 2.5. Try criterion='entropy' and compare the boundary. section 9.4

decision_tree = DecisionTreeClassifier()
decision_tree.fit(features, labels)

Inspect the compact fit call that trains a decision tree from prepared features and labels. section 9.4

How Grokking Machine Learning covers it

How deep it goes
Demonstrates model fitting, graphical boundaries, accuracy, and selected hyperparameters without detailing library internals.
Examples
Uses a two-feature triangle-and-square dataset, a linear SVM dataset, and Pandas DataFrames containing numerical features and labels.
What it assumes
Assumes prepared Pandas data, feature and label separation, and basic familiarity with numerical and categorical features.
What you can do after
Apply it via Python to fit classifiers, inspect boundaries, adjust hyperparameters, and evaluate model performance.
How it connects
Connects decision trees and support vector machines with feature selection, one-hot encoding, grid search, and k-fold cross-validation.

Also explained in

Compare how 5 books explain scikit-learn →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.