View ELSO Logistic Regression (PyMC 2).ipynb
1 2 3 4 5 6 7 8 9 10
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
View ELSO Logistic Regression.ipynb
1 2 3 4 5 6 7 8 9 10
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
View lasso_missing_py2.py
1 2 3 4 5 6 7 8 9 10
from pymc import *
import numpy as np
import pandas as pd
from numpy.ma import masked_values
 
# Import data, filling missing values with sentinels (-999)
test_scores = pd.read_csv('data/test_scores.csv')
 
# Extract variables: test score, gender, number of siblings, previous disability, age,
# mother with HS education or better, hearing loss identified by 3 months of age
View pymarkdown_bug_out.md

Fitting Models to Data

In the first chapter, we learned that while Bayes' formula is simple and its derivation is straightforward, using it to estimate model parameters is hampered by the fact that its calculation typically involves multidimensional integration that is rarely computable in closed form. Most useful Bayesian models, therefore, require computational methods in order to obtain reasonable estimates. Now that we have some Python at our disposal, we will make use of them by stepping through a selection of numerical methods for calculating Bayesian models.

As a motivating example, we will use some real data to build and estimate a simple parametric model. Specifically, we are looking at some measurements taken from subjects in a medical research study, and trying to fit a normal distribution to the weight of the group of patients.

>>> import numpy as np
>>> import pandas as pd
View pymarkdown_bug.md

Fitting Models to Data

In the first chapter, we learned that while Bayes' formula is simple and its derivation is straightforward, using it to estimate model parameters is hampered by the fact that its calculation typically involves multidimensional integration that is rarely computable in closed form. Most useful Bayesian models, therefore, require computational methods in order to obtain reasonable estimates. Now that we have some Python at our disposal, we will make use of them by stepping through a selection of numerical methods for calculating Bayesian models.

As a motivating example, we will use some real data to build and estimate a simple parametric model. Specifically, we are looking at some measurements taken from subjects in a medical research study, and trying to fit a normal distribution to the weight of the group of patients.

View hospitalization_rates.py
1 2 3 4 5 6 7 8 9
import pymc3 as pm
import numpy as np
 
# 1-year-old children in Jordan
kids = np.array([180489, 191817, 190830])
# Proportion of population in Amman
amman_prop = 0.35
# infant RSV cases in Al Bashir hostpital
rsv_cases = np.array([40, 59, 65])
View Cox Model (PyMC 3).ipynb
1 2 3 4 5 6 7 8 9 10
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
View disease_transmission2.py
1 2 3 4 5 6 7 8 9 10
def measles_model(obs_date, confirmation=True, all_traces=False):
n_districts, n_periods, n_age_groups = I_obs.shape
### Confirmation sub-model
if confirmation:
 
# Specify priors on age-specific means
age_classes = np.unique(age_index)
View disease_transmission3.py
1 2 3 4 5 6 7 8 9
obs_date = '1997-06-15'
 
 
with Model() as june_model:
n_districts, n_periods, n_age_groups = I_obs.shape
### Confirmation sub-model
 
View getting_started.ipynb
1 2 3 4 5 6 7 8 9 10
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Probabilistic Programming in Python using PyMC\n",
"\n",
"Authors: John Salvatier, Thomas V. Wiecki, Christopher Fonnesbeck\n",
"\n",
Something went wrong with that request. Please try again.