【问题标题】:pymatch giving error when fitting: Unable to coerce to Series, length must be 1: given xxx拟合时pymatch给出错误:无法强制转换为系列,长度必须为1:给定xxx
【发布时间】:2019-09-03 12:00:53
【问题描述】:

我正在尝试使用 pymatch 构建分数匹配。不幸的是,我收到以下错误

Fitting Models on Balanced Samples: 1\200Error: Unable to coerce to Series, length must be 1: given 1898

这是我的代码

from sklearn.datasets.samples_generator import make_blobs
from pymatch.Matcher import Matcher
import pandas as pd
import numpy as np

X, y = make_blobs(n_samples=5000, centers=2, n_features=2, cluster_std=3.5)
df = pd.DataFrame(dict(x=X[:,0], y=X[:,1], label=y))
df['population'] = np.random.choice([1, 0], size=len(df), p=[0.8, 0.2])

control = df[df.label == 1]
test = df[df.label == 0]

m = Matcher(test, control, yvar="population", exclude=['label'])

m.fit_scores(balance=True, nmodels=200)

如果我运行此代码,我将收到错误消息。我很确定我之前能够运行它,但是在更改了一些版本之后,它就不再起作用了。不幸的是,我无法通过回到以前的版本来修复它,所以不确定这里发生了什么......

【问题讨论】:

    标签: python


    【解决方案1】:

    降级 pandas 对我不起作用,但我发现问题出在哪里。

    是 Matcher.py 的 _scores_to_accuracy() 方法出错。我下载了源文件,在本地机器上编辑了函数,现在可以正常工作了。

    https://github.com/benmiroglio/pymatch/issues/23

    【讨论】:

      【解决方案2】:

      请将您的 pandas 降级到 0.23.4 版。

      使用代码:

      pip install pandas==0.23.4
      

      【讨论】:

        猜你喜欢
        • 2020-12-14
        • 2021-04-22
        • 2020-03-08
        • 2021-05-18
        • 2022-01-24
        • 2011-08-17
        • 1970-01-01
        • 1970-01-01
        • 2020-01-21
        相关资源
        最近更新 更多