Qu

learning_curve

Builtin index · Statistics & ML

result = learning_curve(fit, X, y, [extra...], [sizes=], [folds=5], [shuffle=true], [seed=], [metric="auto"])

Input: fit, X, y, extra..., sizes, folds, shuffle, seed, metric · Output: result

What it is

How a model's score changes with the amount of training data. Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds). For each fold the model is fitted on the first s rows of the other folds, for each s in sizes= (the rows come in the shuffled order, so each training set contains the smaller ones), and scored on those s rows (training score) and on the held-out fold (validation score). sizes= is a vector: entries all at most 1 are fractions of the smallest training fold (n - ceil(n / folds) rows), the default being [0.2, 0.4, 0.6, 0.8, 1.0]; otherwise they are whole row counts no larger than that, the same for every fold (a fraction rounds to the nearest whole row, at least 1).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = learning_curve(fit, X, y, [extra...], [sizes=], [folds=5], [shuffle=true], [seed=], [metric="auto"])
fit —Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
X —Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
y —Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
extra... optional, repeatableTakes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
sizes vector, optionalsizes= is a vector: entries all at most 1 are fractions of the smallest training fold (n - ceil(n / folds) rows), the default being [0.2, 0.4, 0.6, 0.8, 1.0].
folds optional (default 5)Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
shuffle optional (default true)Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
seed optionalTakes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
metric optional (default "auto")Takes the same fit, X, y, extra..., folds=, shuffle=, seed= and metric= as cross_val, and deals the rows into folds the same way (same seed=, same folds).
result vector
Returns {sizes, train_mean, train_std, val_mean, val_std, train_scores, val_scores, folds, metric}: sizes the row counts actually used, the *_mean and *_std vectors one entry per size (population standard deviation over the folds), and train_scores / val_scores the sizes x folds matrices behind them, so plot(r.sizes, r.train_mean) and plot(r.sizes, r.val_mean) draw the curve. A large gap between the two that closes as sizes grows says more data would help; two low curves that meet say the model is too simple. Errors: folds outside 2..n, a sizes entry that is not positive or larger than the smallest training fold, fractions mixed with row counts, an unknown metric.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

xl = linspace(0, 10, 60)
yl = 3 * xl + 1
r = learning_curve(knn_model, xl, yl, 1, seed = 11)
print("rows:       {r.sizes}")
print("train R2:   {round(r.train_mean, 4)}")
print("validation: {round(r.val_mean, 4)}")
output
rows:       [10, 19, 29, 38, 48]
train R2:   [1, 1, 1, 1, 1]
validation: [0.9394, 0.9832, 0.9917, 0.9936, 0.9949]

from statistics-ml

How it works

learning_curve(fit, X, y, [extra...], [sizes=], [folds=5], [shuffle=true], [seed=], [metric=]) -- cross_val's argument shape; train and validation scores at growing training-set sizes.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.