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

  1. 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.
  2. A Promise From a Sorted List (Easy, free): Conformal prediction turns any model's guess into a range with a guarantee attached.
  3. Dot Product (Easy): Given two arrays of the same length, return their dot product.
  4. Euclidean Distance (Easy): Given two points with any number of coordinates, return the straight-line distance between them, rounded to 3 decimals.
  5. Model Accuracy (Easy): Given predictions and true labels, return the fraction the model got right, rounded to 3 decimals.
  6. 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.
  7. Train/Test Split (Easy): Given n samples and a training ratio, return [trainCount, testCount].
  8. Crowded Enough to Count (Medium, free): DBSCAN finds clusters of any shape by looking for crowded places.
  9. One Question, Best Asked (Medium, free): A decision tree is built one split at a time, and each split is this puzzle.
  10. Ranked the Right Way Round (Medium, free): AUC sounds like calculus and is really a count.
  11. Spread the Seeds (Medium, free): k-means gives bad clusters when its starting centers land close together.
  12. 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.
  13. Confusion Matrix (Medium): Given predictions and true labels, both 0 or 1, return [truePositives, falsePositives, falseNegatives, trueNegatives].
  14. Cosine Similarity (Medium): Given two vectors a and b, return their cosine similarity, rounded to 3 decimals.
  15. Gini Impurity (Medium): Given a list of labels, return the Gini impurity, rounded to 3 decimals.
  16. Information Entropy (Medium): Given a list of labels, return the Shannon entropy in bits, rounded to 3 decimals.
  17. L2 Normalize (Medium): Given a vector, scale it to length 1 and return it, rounded to 3 decimals.
  18. Linear Prediction (Medium): Given weights, a bias, and an input x, return the model's prediction, rounded to 3 decimals.
  19. Logistic Prediction (Medium): Given weights, a bias, and an input x, return the predicted probability, rounded to 4 decimals.
  20. Mean Squared Error (Medium): Given predictions and targets, return the mean squared error, rounded to 3 decimals.
  21. Min-Max Scaling (Medium): Given a list of numbers, scale them into the range 0 to 1, rounded to 3 decimals.
  22. Precision (Medium): Given predictions and true labels, both 0 or 1, return the precision, rounded to 3 decimals.
  23. R-Squared Score (Medium): Given predictions and actual targets, return the R-squared score, rounded to 3 decimals.
  24. Recall (Medium): Given predictions and true labels, both 0 or 1, return the recall, rounded to 3 decimals.
  25. Z-Score Standardize (Medium): Given a list of numbers, return each one's z-score, rounded to 3 decimals.
  26. 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.
  27. k-Means Assignment (Hard): Given a list of points and a list of centroids, return the index of the closest centroid for each point.
  28. 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