Skip to content

Commit b597e9a

Browse files
committed
Fix continuous GLMMEncoder
1 parent 0a5eb00 commit b597e9a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

category_encoders/glmm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _train(self, X, y):
277277
estimate = pd.Series(md.vc_mean, index=index_names)
278278
else:
279279
# Regression, returns (regularized) mean deviation of the observation's category from the global mean
280-
md = smf.mixedlm('target ~ 1', data, groups=data[col]).fit()
280+
md = smf.mixedlm('target ~ 1', data, groups=data['feature']).fit()
281281
tmp = dict()
282282
for key, value in md.random_effects.items():
283283
tmp[key] = value[0]

tests/test_glmm.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import numpy as np
2+
from unittest2 import TestCase
3+
import category_encoders as encoders
4+
import tests.helpers as th
5+
6+
# data definitions
7+
X = th.create_dataset(n_rows=100)
8+
np_y = np.random.randn(100) > 0.5
9+
10+
class TestGLMMEncoder(TestCase):
11+
def test_continuous(self):
12+
cols = ['unique_str', 'underscore', 'extra', 'none', 'invariant', 321, 'categorical', 'na_categorical', 'categorical_int']
13+
enc = encoders.GLMMEncoder(cols=cols, binomial_target=False)
14+
enc.fit(X, np_y)
15+
th.verify_numeric(enc.transform(X))
16+
17+
def test_binary(self):
18+
cols = ['unique_str', 'underscore', 'extra', 'none', 'invariant', 321, 'categorical', 'na_categorical', 'categorical_int']
19+
enc = encoders.GLMMEncoder(cols=cols, binomial_target=True)
20+
enc.fit(X, np_y)
21+
th.verify_numeric(enc.transform(X))

0 commit comments

Comments
 (0)