Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_term_split(diabetes_data):
# Split a continuous fixed variable
model = Model(diabetes_data)
model.add_term('BMI', split_by='age_grp')
assert model.terms['BMI'].data.shape == (442, 3)
# Split a categorical fixed variable
model.reset()
model.add_term('BMI', split_by='age_grp', categorical=True)
assert model.terms['BMI'].data.shape == (442, 489)
# Split a continuous random variable
model.reset()
model.add_term('BMI', split_by='age_grp', categorical=False, random=True)
assert model.terms['BMI'].data.shape == (442, 3)
# Split a categorical random variable
model.reset()
model.add_term('BMI', split_by='age_grp', categorical=True, random=True)
t = model.terms['BMI'].data
assert isinstance(t, dict)
assert t['age_grp[0]'].shape == (442, 83)
def test_term_init(diabetes_data):
model = Model(diabetes_data)
term = Term(model, 'BMI', diabetes_data['BMI'])
# Test that all defaults are properly initialized
assert term.name == 'BMI'
assert term.categorical == False
assert term.type_ == 'fixed'
assert term.levels is not None
assert term.data.shape == (442, 1)
def test_model_init_and_intercept(diabetes_data):
model = Model(diabetes_data, intercept=True)
assert hasattr(model, 'data')
assert 'Intercept' in model.terms
assert len(model.terms) == 1
assert model.y is None
assert hasattr(model, 'backend')
model = Model(diabetes_data)
assert 'Intercept' not in model.terms
assert not model.terms
def test_model_init_and_intercept(diabetes_data):
model = Model(diabetes_data, intercept=True)
assert hasattr(model, 'data')
assert 'Intercept' in model.terms
assert len(model.terms) == 1
assert model.y is None
assert hasattr(model, 'backend')
model = Model(diabetes_data)
assert 'Intercept' not in model.terms
assert not model.terms
def base_model(diabetes_data):
return Model(diabetes_data)