All puzzles › Machine Learning
Machine Learning Practice Problems
28 puzzles (7 easy, 18 medium, 3 hard), 8 free, in Python, JavaScript and C++.
Metrics, distances, k-NN and the math behind learning from data.
The puzzles, easiest first
- A Bag With a Fixed Number of Pockets (Easy, free): A model needs a fixed-length vector, but the vocabulary of real text never stops growing.
- A Promise From a Sorted List (Easy, free): Conformal prediction turns any model's guess into a range with a guarantee attached.
- Dot Product (Easy): Given two arrays of the same length, return their dot product.
- Euclidean Distance (Easy): Given two points with any number of coordinates, return the straight-line distance between them, rounded to 3 decimals.
- Model Accuracy (Easy): Given predictions and true labels, return the fraction the model got right, rounded to 3 decimals.
- One-Hot Encode (Easy): Given a class index and the number of classes, return an array of zeros with a single 1 at that index.
- Train/Test Split (Easy): Given n samples and a training ratio, return [trainCount, testCount].
- Crowded Enough to Count (Medium, free): DBSCAN finds clusters of any shape by looking for crowded places.
- One Question, Best Asked (Medium, free): A decision tree is built one split at a time, and each split is this puzzle.
- Ranked the Right Way Round (Medium, free): AUC sounds like calculus and is really a count.
- Spread the Seeds (Medium, free): k-means gives bad clusters when its starting centers land close together.
- Try the Arm You Know Least About (Medium, free): A bandit algorithm has to choose between options it has tried a lot and options it has barely tried.
- Confusion Matrix (Medium): Given predictions and true labels, both 0 or 1, return [truePositives, falsePositives, falseNegatives, trueNegatives].
- Cosine Similarity (Medium): Given two vectors a and b, return their cosine similarity, rounded to 3 decimals.
- Gini Impurity (Medium): Given a list of labels, return the Gini impurity, rounded to 3 decimals.
- Information Entropy (Medium): Given a list of labels, return the Shannon entropy in bits, rounded to 3 decimals.
- L2 Normalize (Medium): Given a vector, scale it to length 1 and return it, rounded to 3 decimals.
- Linear Prediction (Medium): Given weights, a bias, and an input x, return the model's prediction, rounded to 3 decimals.
- Logistic Prediction (Medium): Given weights, a bias, and an input x, return the predicted probability, rounded to 4 decimals.
- Mean Squared Error (Medium): Given predictions and targets, return the mean squared error, rounded to 3 decimals.
- Min-Max Scaling (Medium): Given a list of numbers, scale them into the range 0 to 1, rounded to 3 decimals.
- Precision (Medium): Given predictions and true labels, both 0 or 1, return the precision, rounded to 3 decimals.
- R-Squared Score (Medium): Given predictions and actual targets, return the R-squared score, rounded to 3 decimals.
- Recall (Medium): Given predictions and true labels, both 0 or 1, return the recall, rounded to 3 decimals.
- Z-Score Standardize (Medium): Given a list of numbers, return each one's z-score, rounded to 3 decimals.
- Never Go Down (Hard, free): Sometimes all you know about a curve is that it must never go down: a higher model score should not mean a lower probability.
- k-Means Assignment (Hard): Given a list of points and a list of centroids, return the index of the closest centroid for each point.
- k-Nearest Neighbors (Hard): Given labeled points, a query point, and k, return the label the k closest points vote for.
Practice another pattern
Or browse by subject
Browse all 676 puzzles