File: graphics_plot_fit_ex.py

package info (click to toggle)
statsmodels 0.14.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,956 kB
  • sloc: python: 254,365; f90: 612; sh: 560; javascript: 337; asm: 156; makefile: 145; ansic: 32; xml: 9
file content (35 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""

Created on Monday April 1st 2013

Author: Padarn Wilson

"""

# Load the Statewide Crime data set and perform linear regression with
#    'poverty' and 'hs_grad' as variables and 'murder' as the response


import matplotlib.pyplot as plt
import numpy as np

import statsmodels.api as sm

data = sm.datasets.statecrime.load_pandas().data
murder = data['murder']
X = data[['poverty', 'hs_grad']].copy()
X['constant'] = 1

y = murder
model = sm.OLS(y, X)
results = model.fit()

# Create a plot just for the variable 'Poverty':

fig, ax = plt.subplots()
fig = sm.graphics.plot_fit(results, 0, ax=ax)
ax.set_ylabel("Murder Rate")
ax.set_xlabel("Poverty Level")
ax.set_title("Linear Regression")

plt.show()