benmiroglio / pymatch

MIT License
272 stars 128 forks source link

Error in Example.ipynb "ValueError: negative dimensions are not allowed" #38

Open antgonza opened 4 years ago

antgonza commented 4 years ago

While following the tutorial, I hit the error below, which seems to be caused by: https://stackoverflow.com/a/19939003.

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/pymatch/Matcher.py in init(self, test, control, yvar, formula, exclude) 47 self.matched_data = [] 48 self.y, self.X = patsy.dmatrices('{} ~ {}'.format(yvar, '+'.join(self.xvars)), data=self.data, ---> 49 return_type='dataframe') 50 self.xvars = [i for i in self.data.columns if i not in self.exclude] 51 self.test= self.data[self.data[yvar] == True]

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/highlevel.py in dmatrices(formula_like, data, eval_env, NA_action, return_type) 308 eval_env = EvalEnvironment.capture(eval_env, reference=1) 309 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env, --> 310 NA_action, return_type) 311 if lhs.shape[1] == 0: 312 raise PatsyError("model is missing required outcome variables")

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/highlevel.py in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type) 163 return iter([data]) 164 design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env, --> 165 NA_action) 166 if design_infos is not None: 167 return build_design_matrices(design_infos, data,

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/highlevel.py in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action) 68 data_iter_maker, 69 eval_env, ---> 70 NA_action) 71 else: 72 return None

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/build.py in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action) 719 term_to_subterm_infos = _make_subterm_infos(termlist, 720 num_column_counts, --> 721 cat_levels_contrasts) 722 assert isinstance(term_to_subterm_infos, OrderedDict) 723 assert frozenset(term_to_subterm_infos) == frozenset(termlist)

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/build.py in _make_subterm_infos(terms, num_column_counts, cat_levels_contrasts) 626 coded = code_contrast_matrix(factor_coding[factor], 627 levels, contrast, --> 628 default=Treatment) 629 contrast_matrices[factor] = coded 630 subterm_columns *= coded.matrix.shape[1]

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/contrasts.py in code_contrast_matrix(intercept, levels, contrast, default) 600 return contrast.code_with_intercept(levels) 601 else: --> 602 return contrast.code_without_intercept(levels) 603

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/patsy/contrasts.py in code_without_intercept(self, levels) 181 else: 182 reference = _get_level(levels, self.reference) --> 183 eye = np.eye(len(levels) - 1) 184 contrasts = np.vstack((eye[:reference, :], 185 np.zeros((1, len(levels) - 1)),

~/miniconda3/envs/pymatch/lib/python3.6/site-packages/numpy/lib/twodim_base.py in eye(N, M, k, dtype, order) 199 if M is None: 200 M = N --> 201 m = zeros((N, M), dtype=dtype, order=order) 202 if k >= M: 203 return m

ValueError: negative dimensions are not allowed

antgonza commented 4 years ago

Realized that the error comes when I use the original Kaggle dataset (loan.csv) but the error is not present when using the file in this repo. Leaving issue open in case this is not expected.

antgonza commented 4 years ago

Well, then I hit: https://github.com/benmiroglio/pymatch/issues/34, https://github.com/benmiroglio/pymatch/issues/23

arthi-pfizer commented 2 years ago

I am getting the same error. Was this fixed ?