<jupyter_start><jupyter_text>Example using skGLMM with user's choice of R package. Here we show how to use mgcv's 'bam' by including it in the pacman_call: Generalized additive models for very large datasets<jupyter_code>import numpy as np
import pandas as pd

pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
!pip3 install git+https://github.com/stanbiryukov/sklearn-GLMM
from pyGLMM import skGLMM, r_formula
# 1 millions rows
from sklearn import datasets
X, y = datasets.make_classification(n_samples=1000000, n_features=20,
                                    n_informative=2, n_redundant=2, random_state=1850)

df = pd.DataFrame(X)
df.columns = ['c_' + str(x) for x in df.columns]
df['target'] = y
df.head(10)
form = r_formula(df, dependent_var='target')
call = "bam(formula, data=df, family=binomial())"
call = call.replace('formula', form)
call
Xcols = [x for x in df.columns if x not in ['target']]
ml = skGLMM(r_call = call, pacman_call = 'pacman::p_load(mgcv)')
ml.fit(df[Xcols], df['target'])
ml.summary()
ml.score(df[Xcols], df['target'])
phat = ml.predict(df[Xcols], parallel=True)
phat.shape<jupyter_output>|                                                              |   0%, ETA NA
  |====================                                       |  33%, ETA 00:03
  |=======================================                    |  67%, ETA 00:01
  |=======================================================| 100%, Elapsed 00:02
{'fraction_non_alphanumeric': 0.19389110225763612, 'fraction_numerical': 0.03253652058432935, 'mean_word_length': 3.4851190476190474, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '468876', 'license': 'MIT', 'n_tokens_mistral': 532, 'n_tokens_neox': 474, 'n_words': 125, 'path': 'examples/02_extend_models.ipynb', 'repo_name': 'stanbiryukov/sklearn-GLMM', 'size': '1506'}