pmlearn.linear_model package

Submodules

pmlearn.linear_model.base module

Generalized Linear models.

class pmlearn.linear_model.base.BayesianLinearClassifierMixin[source]

Bases: sklearn.base.ClassifierMixin

Mixin for linear classifiers models in pmlearn

fit(X, y, cats, inference_type='advi', minibatch_size=None, inference_args=None)[source]

Train the Hierarchical Logistic Regression model

Parameters:
  • X (numpy array, shape [n_samples, n_features]) –
  • y (numpy array, shape [n_samples, ]) –
  • cats (numpy array, shape [n_samples, ]) –
  • inference_type (string, specifies which inference method to call.) – Defaults to ‘advi’. Currently, only ‘advi’ and ‘nuts’ are supported
  • minibatch_size (number of samples to include in each minibatch for) – ADVI, defaults to None, so minibatch is not run by default
  • inference_args (dict, arguments to be passed to the inference methods.) – Check the PyMC3 docs for permissable values. If no arguments are specified, default values will be set.
predict(X, cats)[source]

Predicts labels of new data with a trained model

Parameters:
  • X (numpy array, shape [n_samples, n_features]) –
  • cats (numpy array, shape [n_samples, ]) –
predict_proba(X, cats, return_std=False)[source]

Predicts probabilities of new data with a trained Hierarchical Logistic Regression

Parameters:
  • X (numpy array, shape [n_samples, n_features]) –
  • cats (numpy array, shape [n_samples, ]) –
  • return_std (Boolean flag of whether to return standard deviations with) –
  • probabilities. Defaults to False. (mean) –
score(X, y, cats)[source]

Scores new data with a trained model.

Parameters:
  • X (numpy array, shape [n_samples, n_features]) –
  • y (numpy array, shape [n_samples, ]) –
  • cats (numpy array, shape [n_samples, ]) –
class pmlearn.linear_model.base.LinearRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.base.BayesianRegressorMixin

Linear Regression built using PyMC3.

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None

pmlearn.linear_model.logistic module

Logistic regression models.

class pmlearn.linear_model.logistic.HierarchicalLogisticRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.linear_model.base.BayesianLinearClassifierMixin

Custom Hierachical Logistic Regression built using PyMC3.

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None
class pmlearn.linear_model.logistic.LogisticRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.linear_model.base.BayesianLinearClassifierMixin

Bayesian Logistic Regression built using PyMC3

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None

Module contents

The pmlearn.linear_model module implements generalized linear models. It includes Bayesian Regression, Bayesian Logistic Regression, Hierarchical Logistic Regression.

class pmlearn.linear_model.LinearRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.base.BayesianRegressorMixin

Linear Regression built using PyMC3.

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None
class pmlearn.linear_model.HierarchicalLogisticRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.linear_model.base.BayesianLinearClassifierMixin

Custom Hierachical Logistic Regression built using PyMC3.

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None
class pmlearn.linear_model.LogisticRegression[source]

Bases: pmlearn.base.BayesianModel, pmlearn.linear_model.base.BayesianLinearClassifierMixin

Bayesian Logistic Regression built using PyMC3

create_model()[source]

Creates and returns the PyMC3 model.

Note: The size of the shared variables must match the size of the training data. Otherwise, setting the shared variables later will raise an error. See http://docs.pymc.io/advanced_theano.html

Returns:
Return type:the PyMC3 model
load(file_prefix)[source]

Loads a saved version of the trace, and custom param files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to load the) –
  • trace for this model. (saved) – Ex: given file_prefix = “path/to/file/” This will attempt to load “path/to/file/trace.pickle”
  • load_custom_params (Boolean flag to indicate whether custom parameters) –
  • be loaded. Defaults to False. (should) –
Returns:

custom_params

Return type:

Dictionary of custom parameters

save(file_prefix)[source]

Saves the trace and custom params to files with the given file_prefix.

Parameters:
  • file_prefix (str, path and prefix used to identify where to save the) –
  • for this model. (trace) – Ex: given file_prefix = “path/to/file/” This will attempt to save to “path/to/file/trace.pickle”
  • custom_params (Dictionary of custom parameters to save.) – Defaults to None