Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

alkaline-ml / statsmodels   python

Repository URL to install this package:

Version: 0.11.1 

/ genmod / tests / results / elastic_net_generate_tests.py

import numpy as np

"""
Generate data sets for testing elastic net fits of GLMs.
"""

n = 200
p = 5

# Logistic
exog = np.random.normal(size=(n, p))
lin_pred = exog.sum(1) * 0.2
exp_val = 1 / (1 + np.exp(-lin_pred))
endog = 1 * (np.random.uniform(size=n) < exp_val)
mat = np.concatenate((endog[:, None], exog), axis=1)
np.savetxt("enet_binomial.csv", mat, fmt="%.2f", delimiter=",")

# Poisson
exog = np.random.normal(size=(n, p))
lin_pred = exog.sum(1) * 0.2
exp_val = np.exp(lin_pred)
endog = np.random.poisson(exp_val)
mat = np.concatenate((endog[:, None], exog), axis=1)
np.savetxt("enet_poisson.csv", mat, fmt="%.2f", delimiter=",")