使用sklearn、matplotlib等库时遇到的问题汇总

  1. sklearn接口下的xgboost多分类时报错:label and prediction size not match, hint: use merror or mlogloss for multi-class classification
    解决:参数配置问题,sklearn接口下的xgboost时,配置更改如下:objective='multi:softprob', num_class=3,eval_metric="merror"

  2. matplotlib无法显示中文和负号
    a) 临时解决方法:(本人方法)

    import matplotlib.pyplot as plt
    plt.rcParams['font.sans-serif'] = ['SimHei']  #显示中文
    plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
    

    b) 一劳永逸法(本人没有尝试)

    找到matplotlib包的所在位置,一般在D:\anaconda\Lib\site-packages\matplotlib\mpl-data,里面有个配置文件,matplotlibrc,用spyder打开。
    在里面找到相应的地方改掉

    显示负号:

    #axes.unicode_minus  : True →改成axes.unicode_minus  : False
    

    正式显示中文:

    #font.family : sans-serif  →去掉#号
    
发布了143 篇原创文章 · 获赞 161 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/vivian_ll/article/details/103282976