python - pymatch 在拟合 : Unable to coerce to Series, 长度必须为 1 时给出错误:给定 xxx

标签 python

我正在尝试使用 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)

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

最佳答案

降级 pandas 对我不起作用,但我发现了问题所在。

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

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

关于python - pymatch 在拟合 : Unable to coerce to Series, 长度必须为 1 时给出错误:给定 xxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55656401/

相关文章:

python - 如何在pycharm上安装tkinter

python - 列切片 Pandas

python - 表单从模型接收旧数据

python - 用 Python 编写 HDF5 文件的最快方法是什么?

python - OpenCV python : Show images in channel's color and not in grayscale

python - 如果数组 0 发生更改,则保持数组大小不变

python - unicodedata.digit 和 unicodedata.numeric 有什么区别?

python - Selenium - 获取页面中的所有 iframe(甚至是嵌套的)?

Python While 循环条件评估

python - 当从 csv 读取到数据框 pandas python 时,dict 对象转换为字符串