{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n",
"Coefficients: [ 72.88279832 -0.08844242]\n",
"Intercept: 0.000210747768548\n",
"P-Values: [ 0.00000000e+000 0.00000000e+000 5.96972978e-203]\n",
"R-Squared: 0.656632624649\n"
]
}
],
"source": [
"%pylab inline\n",
"import pylab as pl\n",
"import numpy as np\n",
"#from sklearn import datasets, linear_model\n",
"import pandas as pd\n",
"import statsmodels.api as sm\n",
"\n",
"# import the cleaned up dataset\n",
"df = pd.read_csv('../datasets/loanf.csv')\n",
"\n",
"intrate = df['Interest.Rate']\n",
"loanamt = df['Loan.Amount']\n",
"fico = df['FICO.Score']\n",
"\n",
"# reshape the data from a pandas Series to columns \n",
"# the dependent variable\n",
"y = np.matrix(intrate).transpose()\n",
"# the independent variables shaped as columns\n",
"x1 = np.matrix(fico).transpose()\n",
"x2 = np.matrix(loanamt).transpose()\n",
"\n",
"# put the two columns together to create an input matrix \n",
"# if we had n independent variables we would have n columns here\n",
"x = np.column_stack([x1,x2])\n",
"\n",
"# create a linear model and fit it to the data\n",
"X = sm.add_constant(x)\n",
"model = sm.OLS(y,X)\n",
"f = model.fit()\n",
"\n",
"print 'Coefficients: ', f.params[0:2]\n",
"print 'Intercept: ', f.params[2]\n",
"print 'P-Values: ', f.pvalues\n",
"print 'R-Squared: ', f.rsquared\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.core.display import HTML\n",
"def css_styling():\n",
" styles = open(\"../styles/custom.css\", \"r\").read()\n",
" return HTML(styles)\n",
"css_styling()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 0
}