Skip to content

Patsy dmatrices compatibility #5323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kavvkon opened this issue Feb 18, 2020 · 1 comment
Open

Patsy dmatrices compatibility #5323

kavvkon opened this issue Feb 18, 2020 · 1 comment

Comments

@kavvkon
Copy link

kavvkon commented Feb 18, 2020

Generating a dataframe with features generated by dmatrices may include unallowed characters that result to ValueError.

MRE modified from patsy documentation

>>> from patsy import dmatrices, demo_data
>>>data = demo_data("a", "b", "x1", "x2", "y", "z column")

>>>y,X = dmatrices("y ~ x1 + a:x2", data, return_type='dataframe')
>>>X
   Intercept        x1  a[a1]:x2  a[a2]:x2
0        1.0  1.764052 -0.103219 -0.000000
1        1.0  0.400157  0.410599  0.000000
2        1.0  0.978738  0.000000  0.144044
3        1.0  2.240893  0.000000  1.454274
4        1.0  1.867558  0.761038  0.000000
5        1.0 -0.977278  0.121675  0.000000
6        1.0  0.950088  0.000000  0.443863
7        1.0 -0.151357  0.000000  0.333674

This results to :

model = xgb.XGBRegressor()
model = model.fit(X, y)

ValueError: feature_names may not contain [, ] or <`

What is the real reason that these characters are not allowed ? It is not the case with the rest of scikit-learn compat packages

@trivialfis
Copy link
Member

I guess it's because the current implementation parses a Scikit Learn compatible model dump to plot the importance or export the model as a dataframe, and that format uses these characters. We can change it to JSON to remove the limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants