Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unhashable type: 'numpy.ndarray' #94

Closed
Jarye0612 opened this issue Aug 31, 2022 · 8 comments
Closed

TypeError: unhashable type: 'numpy.ndarray' #94

Jarye0612 opened this issue Aug 31, 2022 · 8 comments

Comments

@Jarye0612
Copy link

执行安装命令pip install scorecardpy后,运行Example代码报错,
出错语句为:

woe binning ------

bins = sc.woebin(dt_s, y="creditability")
报错信息:
TypeError: unhashable type: 'numpy.ndarray'

@ShichenXie
Copy link
Owner

这个例子的代码有问题,dt_s 并没有定义。

@HEHEOMG
Copy link

HEHEOMG commented Sep 7, 2022

你好,最近我发现使用sc.woebin会报错,TypeError: unhashable type: 'numpy.ndarray',通过尝试,发现在该函数在环境为python3.7的win/mac/linux能正常运行,环境为python3.8的mac/linux也能运行,但在3.8的windows下报错,原因是scorecardpy.woebin.woebin2_init_bin()函数中下面这段代码中,np.unique(x)会产生一个numpy.ndarray类型,应该是pandas版本的原因,将其改成np.unique(x)[0]可解决该问题,

    init_bin = init_bin.groupby('brkp').agg({
      'variable':lambda x: np.unique(x),
      'bin': lambda x: '%,%'.join(x),
      'good': sum,
      'bad': sum
    }).assign(badprob = lambda x: x['bad']/(x['good']+x['bad']))\
    .reset_index()

@Roll113
Copy link

Roll113 commented Sep 15, 2022

pandas最好使用1.4以下的版本

@Jarye0612
Copy link
Author

Jarye0612 commented Sep 16, 2022

这个例子的代码有问题,dt_s 并没有定义。

你好,使用的是本项目readme提供的Example代码,dt_s定义了
刚接触这块内容,还想问下这个项目实现基于哪些文档资料或者链接,是否方便告知下,以了解有些代码为什么这么写?

@Jarye0612
Copy link
Author

你好,最近我发现使用sc.woebin会报错,TypeError: unhashable type: 'numpy.ndarray',通过尝试,发现在该函数在环境为python3.7的win/mac/linux能正常运行,环境为python3.8的mac/linux也能运行,但在3.8的windows下报错,原因是scorecardpy.woebin.woebin2_init_bin()函数中下面这段代码中,np.unique(x)会产生一个numpy.ndarray类型,应该是pandas版本的原因,将其改成np.unique(x)[0]可解决该问题,

    init_bin = init_bin.groupby('brkp').agg({
      'variable':lambda x: np.unique(x),
      'bin': lambda x: '%,%'.join(x),
      'good': sum,
      'bad': sum
    }).assign(badprob = lambda x: x['bad']/(x['good']+x['bad']))\
    .reset_index()

谢谢,改成np.unique(x)[0]这个方法解决了这个问题,但执行readme中的Example代码又报了一个错:ValueError: Number of rows must be a positive integer, not 1.0,通过将scorecardpy-perf.py中 perf_eva 的subplot_nrows,subplot_ncols强制转化为整数解决。解决这两个问题后,在本地环境(本地环境 python3.10.4,pandas1.4.3)运行readme中Example代码运行成功。

@Jarye0612
Copy link
Author

pandas最好使用1.4以下的版本

谢谢,由于本地还有其他功能,更改版本可能影响现有功能

@ShichenXie
Copy link
Owner

pandas 的向前兼容有点问题,可以试试R版本的scorecard,速度更快、也更稳定。python版本的包更新,需要等我处理好手上的其他事情。

CBravoR added a commit to CBravoR/scorecardpy that referenced this issue Mar 27, 2023
OGorkun pushed a commit to OGorkun/scorecardpy that referenced this issue May 20, 2023
@ShichenXie
Copy link
Owner

It should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants