ermutuxia

2020-07-31   阅读量: 2629

python scorecardpy

用scorecardpy库画图出现错误提示:RuntimeWarning: More than 20 figures have been opened.

扫码加入数据分析学习群
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 31 18:59:15 2020
@author: Administrator
"""
#第一步导入相关库
import numpy as np
import pandas as pd
import scorecardpy as sc
import matplotlib as mpl
import matplotlib.pyplot as plt
#第二步准备数据
x_a=pd.DataFrame(np.random.random_integers(1,4,(1000,30)))
x_a.columns=["x"+str(i)for i in x_a.columns]
y_a=pd.DataFrame({'y':['good','bad']}).sample(1000, replace=True)
y_a.reset_index(inplace=True)
data1=pd.concat([x_a,y_a],axis=1)
y_b=pd.DataFrame({'y':['good','bad']}).sample(50, replace=True)
data4 = pd.concat([data1,y_b], ignore_index=True,axis=0)
#第三步画图
bins = sc.woebin(data4, y="y")
sc.woebin_plot(bins)

'''

运行最后一行命令时会出现错误提示如下:

C:\ProgramData\Anaconda3\lib\site-packages\scorecardpy\woebin.py:1203: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).

fig, ax1 = plt.subplots()

C:\ProgramData\Anaconda3\lib\site-packages\scorecardpy\woebin.py:1203: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).

C:\ProgramData\Anaconda3\lib\site-packages\scorecardpy\woebin.py:1203: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).


'''

image.png

#这是什么原因?是因为x变量的个数太多了,超过了画图允许的个数,画图允许的默认个数是20

#把这个参数改大一些,比如改成40就可以画出来了


plt.rcParams['figure.max_open_warning']=40

sc.woebin_plot(bins)

#再执行就可以出结果了

image.png


image.png

image.png

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0005 1 5 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子