Business analytics

Supervised learning

Predict a yes-or-no outcome, comparing logistic regression, a decision tree, nearest neighbours and a random forest fairly.

Supervised learning learns from rows where the answer is known, then predicts it for rows where it isn’t. Four models answer the same question here, and every one is judged only on rows it never trained on.

Your data

Choose a table, then the yes-or-no column to predict (any column with exactly two values) and the columns to predict it from. Every section below uses this choice. A table you loaded under Explore appears here too.

Predictors

Compare models

Logistic regression, a decision tree, nearest neighbours and a random forest, scored the same fair way: the rows are dealt into five folds that keep the yes/no balance, and each model is trained on four folds and scored on the fifth, five times over. Every row ends up predicted by a model that never saw it.

Look closely at

Drawn in colour on the charts and used for feature importance below. The decision tree’s depth is set under A tree you can read.

A tree you can read

A decision tree asks one yes-or-no question at a time, choosing at each step the split that leaves the two sides purest (lowest Gini impurity). A shallow tree is a set of rules a person can check; a deep one fits the training rows better and new rows worse.

These settings also drive the decision tree in Compare models above.

Leaves (rules)
—
AUC across folds
—
AUC on its own training rows
—
The tree, grown on every row

Read down from the top: go left when the answer is yes. Each leaf shows the share of its rows that were yes. Point at a leaf, or focus the tree and use the arrow keys, to see the rules that lead there.

Show the rules as text

    Feature importance

    Which columns does a model lean on? Permutation importance shuffles one column among the held-out rows, breaking its link to the outcome, and measures how far the AUC falls. It works the same way for every model, so the answers are comparable.

    Logistic regression in depth

    Logistic regression is the model you can explain line by line: each coefficient becomes an odds ratio with a confidence interval. Fitted on every row for the reading, and judged on the 30% of rows held back from a separate fit.

    —area under the ROC curve, on the 30% of rows held back

    Accuracy
    —
    Precision
    —
    Recall
    —
    McFadden pseudo-R²
    —
    Odds ratios, fitted on every row
      ROC curve on the held-back rows
      At this threshold

      Sources

      1. Breiman, L., Friedman, J., Olshen, R. & Stone, C. (1984). Classification and Regression Trees. Wadsworth. Breiman, L. (2001). Random forests. Machine Learning 45, 5–32.
      2. Cover, T. & Hart, P. (1967). Nearest neighbor pattern classification. IEEE Transactions on Information Theory 13(1), 21–27. Hastie, T., Tibshirani, R. & Friedman, J. (2009). The Elements of Statistical Learning, 2nd ed., ch. 7 (cross-validation) and ch. 15 (random forests). Springer.
      3. Fisher, A., Rudin, C. & Dominici, F. (2019). All models are wrong, but many are useful: learning a variable’s importance by studying an entire class of prediction models simultaneously. Journal of Machine Learning Research 20(177), 1–81.
      4. Hosmer, D. W., Lemeshow, S. & Sturdivant, R. X. (2013). Applied Logistic Regression, 3rd ed. Wiley. McFadden, D. (1974). Conditional logit analysis of qualitative choice behavior. In Frontiers in Econometrics.
      5. Everything here is computed in your browser. The tree, nearest neighbours and AUC are checked against scikit-learn, and logistic regression against statsmodels, in the site’s automated tests.
      6. All example datasets are synthetic, generated for this page.