LATENT LIBRARY FUNDAMENTALS MachineLearning byHand Core Algorithms Worked Through WithSmall Numbers LATENT LIBRARY EDITORIAL

Machine Learning by Hand

Core Algorithms Worked Through With Small Numbers

Latent Library Editorial

IntroductionIntroduction

There are two common ways to learn machine learning. The first is to call a library function, get a number back and move on. It is fast, but the algorithm remains a black box, and when results look wrong you have little idea why. The second is to start with dense mathematical notation, which is precise but discourages many capable people before they reach the useful ideas.

This book takes a third path. Every core algorithm is worked through by hand, with datasets small enough to fit on a page. You will compute a regression line, run gradient descent for several steps, calculate a probability with logistic regression, choose a decision-tree split, and watch k-means find its clusters. Each formula is described in words before it appears in symbols, and every calculation is shown.

You need only school-level algebra: adding, multiplying, squaring, and reading a simple formula. A calculator helps. If you later use a library such as scikit-learn, you will know exactly what its functions are doing, which settings matter and what can go wrong.

The route through the book

Appendix A contains ten practice problems with full solutions, and Appendix B is a short maths refresher covering every tool the book uses. If a formula ever feels unfamiliar, turn to Appendix B first. Appendix C shows where each idea lives in a standard Python library, so you can move from pencil to code.

How to work through it

Read with a pencil. When a table of numbers appears, cover the right-hand columns and try to compute them yourself before checking. The examples are deliberately tiny so that you can do this; the understanding you gain transfers directly to datasets with millions of rows, where only the bookkeeping changes.

Chapter 1Data, Features and Labels

Rows, features and labels

Machine-learning data is usually arranged as a table. Each row is one example: a house, a customer, an email. Each column describing the example is a feature (also called an input or variable). The column we want to predict is the label (or target).

CustomerVisits last monthAverage basket (€)Has appBought again?
1435yesyes
2112nono
3622yesyes

Here "visits", "average basket" and "has app" are features; "bought again?" is the label.

Kinds of features

Scaling

Many algorithms compare or combine features numerically. If one feature ranges from 0 to 1 and another from 0 to 100,000, the large one can dominate simply because of its units. Two common fixes:

Example: visits of 1, 4 and 6 have min 1 and max 6. Min-max scaled, they become 0, 0.6 and 1.0.

Regression or classification?

You have reached the end of the free sample.
The full book continues with 14 more chapters, plus everything else in its 82 pages.

Get the full book