我正在尝试使用 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()方法中的错误。我下载了源文件,在我的本地机器上编辑了函数,现在它工作正常。
关于python - pymatch 在拟合 : Unable to coerce to Series, 长度必须为 1 时给出错误:给定 xxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55656401/