neuhongke 2021-09-30 17:11 采纳率: 25%
浏览 189

机器学习建模报错 TypeError:plot_learning_curve() got an unexpected keyword argument 'ax'

以下是我的代码,该导入的库没有任何问题,代码检查了多遍依然正确

def plot_learning_curve(estimator,title, X, y,
                        x=None, #选择子图
                        ylim=None, #设置纵坐标的取值范围
                        cv=None, #交叉验证
                        n_jobs=None #设定索要使用的线程
                        ):
    
    train_sizes,train_scores,test_scores = learning_curve(estimator,
                                                           X, y,
                                                           shuffle=True
                                                           ,cv=cv
                                                           ,random_state=420
                                                            ,n_jobs=n_jobs)
   
    ax.set_title(title)#设置标题
    if ax == None:
        ax = plt.gca()
    else:
        ax = plt.figure()
    
    if ylim is not None:
        ax.set_ylim(*ylim)
    ax.set_xlabel("Training examples")
    ax.set_ylabel("Score")
    ax.grid() #绘制网格,不是必须
    ax.plot(train_sizes,np.mean(train_scores, axis=1),'o-',color="r",label="Training score")
    ax.plot(train_sizes,np.mean(test_scores, axis=1),'o-',color="g",label="Test score")
    ax.legend(loc="best")
    return ax
cv = KFold(n_splits=5, shuffle = True, random_state=42)#交叉验证模式
plot_learning_curve(XGBR(n_estimators=100,random_state=420),"XGB",Xtrain,Ytrain,
                    ax=None,cv=cv)
plt.show()

报错如下:
TypeError Traceback (most recent call last)
in
----> 1 plot_learning_curve(XGBR(n_estimators=100,random_state=420),"XGB",Xtrain,Ytrain,
2 ax=None,cv=cv)
3 plt.show()

TypeError:

```python

``` plot_learning_curve() got an unexpected keyword argument 'ax'

  • 写回答

1条回答 默认 最新

  • python收藏家 2021-09-30 17:32
    关注

    ax 没有定义? fig, ax = plt.subplots()
    这个创建的吧

    评论

报告相同问题?

问题事件

  • 创建了问题 9月30日

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算