py-why / py-why/EconML

name 'concatenate' is not defined

Open
#293 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.8k
Forks
827
PR merge metrics
No merged PRs in 30d

Description

Hi all,

I am trying to run @vasilismsr prototype NLSYM_Linear. Everything works fine except when I run cate.fit().
Specifically I have the error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-19-6ec0fce7800f> in <module>
----> 1 cate.fit(y, T, X, Z)

~/EconML/prototypes/dml_iv/dml_iv.py in fit(self, y, T, X, Z, store_final)
    126         for idx, (train, test) in enumerate(splits):
    127             # Estimate h(Z, X) = E[T | Z, X] in cross-fitting manner
--> 128             proj_t[test] = self.model_T_XZ[idx].fit(hstack([X[train], Z[train]]),
    129                                                     T[train]).predict(hstack([X[test],
    130                                                                               Z[test]]))

~/EconML/prototypes/dml_iv/dml_iv.py in hstack(XS)
     37     """
     38     # Confusingly, this needs to concatenate, not stack (stack returns an array with an extra dimension)
---> 39     return concatenate(XS, 1)
     40 
     41 

NameError: name 'concatenate' is not defined

which I guess deals with utilities.py, i.e. it does not find concatenate which is used in hstack. I checked and concatenate seems to be well defined:

    """
    Join a sequence of arrays along an existing axis.

    Parameters
    ----------
    X1, X2, ... : sequence of array_like
        The arrays must have the same shape, except in the dimension
        corresponding to `axis` (the first, by default).

    axis : int, optional
        The axis along which the arrays will be joined.  Default is 0.

    Returns
    -------
    ndarray or SparseArray
        The concatenated array. It will be sparse if the inputs are.
    """
    def conc(*XS):
        return sp.concatenate(XS, axis=axis) if iscoo(XS[0]) else np.concatenate(XS, axis=axis)
    return _apply(conc, *XS)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in prototypes/dml_iv/dml_iv.py at hstack and inspect how concatenate is referenced, then compare that with the concatenate implementation shown from utilities.py. Confirm the missing name is available where hstack runs, and verify that cate.fit(y, T, X, Z) no longer raises this NameError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.