Example

Requirements

It is recommended make virtualenv and install all next packages in this virtualenv.

samplesizelib==0.0.2

Include packages.

import numpy as np

from samplesizelib.linear.statistical import LagrangeEstimator
from samplesizelib.linear.statistical import LikelihoodRatioEstimator
from samplesizelib.linear.statistical import WaldEstimator
from samplesizelib.linear.models import RegressionModel
from samplesizelib.linear.models import LogisticModel

from samplesizelib.linear.heuristic import CrossValidationEstimator
from samplesizelib.linear.heuristic import BootstrapEstimator
from samplesizelib.linear.heuristic import LogisticRegressionEstimator
from samplesizelib.linear.bayesian import APVCEstimator
from samplesizelib.linear.bayesian import ACCEstimator
from samplesizelib.linear.bayesian import ALCEstimator
from samplesizelib.linear.bayesian import MaxUtilityEstimator
from samplesizelib.linear.bayesian import KLEstimator

Preparing the dataset

Generate dataset for regression and classification tasks.

n = 10
m = 300

np.random.seed(0)
X_cl = np.random.randn(m, n)
y_cl = np.random.randint(2, size=m)

np.random.seed(0)
X_rg = np.random.randn(m, n)
y_rg = np.random.randn(m)

Bayesian Metods

Regression task

Example of Bootstrap based method:

model = BootstrapEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of Cross Validation based method:

model = CrossValidationEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Classification task

Example of Logistic Regression method:

model = LogisticRegressionEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of Bootstrap based method:

model = BootstrapEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of Cross Validation based method:

model = CrossValidationEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Bayesian Metods

Regression task

Example of KL-divergence method:

model = KLEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of Max Utility method:

model = MaxUtilityEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of ALC method:

model = ALCEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of ACC method:

model = ACCEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of APVC method:

model = APVCEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Classification task

Example of KL-divergence method:

model = KLEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of Max Utility method:

model = MaxUtilityEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of ALC method:

model = ALCEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of ACC method:

model = ACCEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of APVC method:

model = APVCEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Statictical Metods

Regression task

Example of Lagrange based method:

model = LagrangeEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of Likelihood Ratio based method:

model = LikelihoodRatioEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Example of Wald based method:

model = WaldEstimator(RegressionModel)
ret = model(X_rg, y_rg)

print(ret['m*'])

Classification task

Example of Lagrange based method:

model = LagrangeEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of Likelihood Ratio based method:

model = LikelihoodRatioEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])

Example of Wald based method:

model = WaldEstimator(LogisticModel)
ret = model(X_cl, y_cl)

print(ret['m*'])