Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pymatch giving error when fitting: Unable to coerce to Series, length must be 1: given xxx

Tags:

python

I am trying to build a score matching using pymatch. Unfortunately I am getting the following error

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

Here is my code

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)

if I ran this code I will get the error. I am quite sure that I was able to run this before, but after changing some versions, this doesn't work anymore. Unfortunately I wasn't able to fix it by going back to previous versions, so not sure what's going on here...

like image 637
DarioB Avatar asked Apr 12 '19 16:04

DarioB


1 Answers

Downgrading pandas did not work for me, but I found where the problem is.

It is an error in the method _scores_to_accuracy() of Matcher.py. I downloaded the source file, edited the function on my local machine, and now it works fine.

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

like image 170
Jo-Lynn Zhuo Avatar answered Nov 15 '22 09:11

Jo-Lynn Zhuo