Skip to content
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

fitted ought to check that any new data it receives is compatible with the model #20

Open
null-a opened this issue Oct 1, 2019 · 0 comments

Comments

@null-a
Copy link
Collaborator

null-a commented Oct 1, 2019

I'm aware of one specific problem. It occurs when fitted is passed a data frame in which a categorical column includes a level not present in the data on which inference was performed. In this situation, rows in which the categorical column takes on this superfluous level are coded incorrectly.

import pandas as pd
from brmp import defm
from brmp.fit import fitted
from brmp.design import predictors

df = pd.DataFrame(dict(
    y=[0.,1.],
    a=pd.Categorical(['a0','a1']),
))

fit = defm('y ~ a', df).fit(iter=5)

df2 = pd.DataFrame(dict(
    # level 'a2' is not present in df
    a=pd.Categorical(['a0','a1','a2']),
))

# `fitted` does something like this internally:
data = predictors(fit.formula, df2, fit.metadata, {})

print(data['X'])
# [[1. 0.]   # a0
#  [0. 1.]   # ... and a1 are coded correctly,
#  [0. 0.]]  # ... but the new level is a row of zeros

It's possible that there are further notions of compatibility that we ought to check for.

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

No branches or pull requests

1 participant