MCPcopy Create free account
hub / github.com/Riley702/enhanced_benchmark_tool / plot_learning_curve

Function plot_learning_curve

src/visualizations.py:198–231  ·  view source on GitHub ↗

Plots the learning curve of a model. Args: model: A scikit-learn compatible model. X (pd.DataFrame or np.ndarray): Feature matrix. y (pd.Series or np.ndarray): Target values. cv (int): Number of cross-validation folds. train_sizes (array-like): Propo

(model, X, y, cv=5, train_sizes=np.linspace(0.1, 1.0, 10), scoring="accuracy")

Source from the content-addressed store, hash-verified

196 plt.show()
197
198def plot_learning_curve(model, X, y, cv=5, train_sizes=np.linspace(0.1, 1.0, 10), scoring="accuracy"):
199 """
200 Plots the learning curve of a model.
201
202 Args:
203 model: A scikit-learn compatible model.
204 X (pd.DataFrame or np.ndarray): Feature matrix.
205 y (pd.Series or np.ndarray): Target values.
206 cv (int): Number of cross-validation folds.
207 train_sizes (array-like): Proportions of training data to evaluate.
208 scoring (str): Scoring metric to evaluate model performance.
209
210 Returns:
211 None
212 """
213 train_sizes, train_scores, val_scores = learning_curve(model, X, y, cv=cv, train_sizes=train_sizes, scoring=scoring, n_jobs=-1)
214
215 train_mean = np.mean(train_scores, axis=1)
216 train_std = np.std(train_scores, axis=1)
217 val_mean = np.mean(val_scores, axis=1)
218 val_std = np.std(val_scores, axis=1)
219
220 plt.figure(figsize=(8, 6))
221 plt.plot(train_sizes, train_mean, label="Training Score", marker="o", color="blue")
222 plt.fill_between(train_sizes, train_mean - train_std, train_mean + train_std, alpha=0.2, color="blue")
223 plt.plot(train_sizes, val_mean, label="Validation Score", marker="o", color="red")
224 plt.fill_between(train_sizes, val_mean - val_std, val_mean + val_std, alpha=0.2, color="red")
225
226 plt.xlabel("Training Set Size")
227 plt.ylabel(scoring.capitalize())
228 plt.title("Learning Curve")
229 plt.legend(loc="lower right")
230 plt.grid(alpha=0.5)
231 plt.show()
232
233
234def plot_feature_distribution(df, feature, bins=30):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected