TypeError: plot_learning_curve() got an unexpected keyword argument 'figsize'
时间: 2023-11-18 18:05:57 浏览: 74
This error occurs when the `plot_learning_curve()` function is called with an additional argument `figsize`, which is not defined in the function. This means that the function does not accept the `figsize` argument, and it is causing a TypeError.
To resolve this error, you can remove the `figsize` argument from the function call or modify the `plot_learning_curve()` function to accept the `figsize` argument. If you want to modify the function, you can do so by adding the `figsize` argument to the function definition and using it to set the size of the plot in the function code.
For example:
```python
import matplotlib.pyplot as plt
from sklearn.model_selection import learning_curve
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None, n_jobs=None, train_sizes=np.linspace(.1, 1.0, 5), figsize=None):
if figsize:
plt.figure(figsize=figsize)
plt.title(title)
if ylim is not None:
plt.ylim(*ylim)
plt.xlabel("Training examples")
plt.ylabel("Score")
train_sizes, train_scores, test_scores = learning_curve(estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
train_scores_mean = np.mean(train_scores, axis=1)
train_scores_std = np.std(train_scores, axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1)
plt.grid()
plt.fill_between(train_sizes, train_scores_mean - train_scores_std, train_scores_mean + train_scores_std, alpha=0.1, color="r")
plt.fill_between(train_sizes, test_scores_mean - test_scores_std, test_scores_mean + test_scores_std, alpha=0.1, color="g")
plt.plot(train_sizes, train_scores_mean, 'o-', color="r", label="Training score")
plt.plot(train_sizes, test_scores_mean, 'o-', color="g", label="Cross-validation score")
plt.legend(loc="best")
return plt
```
Now, you can call the `plot_learning_curve()` function with the `figsize` argument:
```python
plot_learning_curve(estimator, 'Learning Curve', X_train, y_train, figsize=(8, 6))
```