Visualización de la curva de aprendizaje con LearningCurveDisplay#
Permite graficar el valor del score vs el tamaño del dataset de entrenamiento.
Se recomienda su construcción usando
from_estimator
y no directamente con la función.
Uso directo (no recomendado)#
[1]:
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.model_selection import LearningCurveDisplay, learning_curve
from sklearn.tree import DecisionTreeClassifier
X, y = load_iris(return_X_y=True)
tree = DecisionTreeClassifier(random_state=0)
train_sizes, train_scores, test_scores = learning_curve(
tree,
X,
y,
)
display = LearningCurveDisplay(
# -------------------------------------------------------------------------
# Numbers of training examples that has been used to generate the learning
# curve.
train_sizes=train_sizes,
# -------------------------------------------------------------------------
# Scores on training sets.
train_scores=train_scores,
# -------------------------------------------------------------------------
# Scores on test set.
test_scores=test_scores,
# -------------------------------------------------------------------------
# The name of the score used in learning_curve. It will be used to decorate
# the y-axis. If None, the generic name "Score" will be used.
score_name="Score",
)
display.plot()
plt.show()
Uso de from_estimator()#
[2]:
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.model_selection import LearningCurveDisplay
from sklearn.tree import DecisionTreeClassifier
X, y = load_iris(return_X_y=True)
tree = DecisionTreeClassifier(random_state=0)
LearningCurveDisplay.from_estimator(tree, X, y)
plt.show()