We're going to pick up where we left off at the end of the exploration and define a linear model with two independent variables determining the dependent variable, Interest Rate.
Our investigation is now defined as:
Investigate FICO Score and Loan Amount as
We're going to pick up where we left off at the end of the exploration and define a linear model with two independent variables determining the dependent variable, Interest Rate.
Our investigation is now defined as:
Investigate FICO Score and Loan Amount as predictors of Interest Rate for the Lending Club sample of 2,500 loans.
We use Multivariate Linear Regression to model Interest Rate variance with FICO Score and Loan Amount using:$$InterestRate = a_0 + a_1 * FICOScore + a_2 * LoanAmount$$
We're going to use modeling software to generate the model coefficients $a_0$, $a_1$ and $a_2$ and then some error estimates that we'll only touch upon lightly at this point.
%pylab inline import pylab as pl import numpy as np #from sklearn import datasets, linear_model import pandas as pd import statsmodels.api as sm # import the cleaned up dataset df = pd.read_csv('../datasets/loanf.csv') intrate = df['Interest.Rate'] loanamt = df['Loan.Amount'] fico = df['FICO.Score'] # reshape the data from a pandas Series to columns # the dependent variable y = np.matrix(intrate).transpose() # the independent variables shaped as columns x1 = np.matrix(fico).transpose() x2 = np.matrix(loanamt).transpose() # put the two columns together to create an input matrix # if we had n independent variables we would have n columns here x = np.column_stack([x1,x2]) # create a linear model and fit it to the data X = sm.add_constant(x) model = sm.OLS(y,X) f = model.fit() print 'Coefficients: ', f.params[0:2] print 'Intercept: ', f.params print 'P-Values: ', f.pvalues print 'R-Squared: ', f.rsquared
Populating the interactive namespace from numpy and matplotlib Coefficients: [ 72.88279832 -0.08844242] Intercept: 0.000210747768548 P-Values: [ 0.00000000e+000 0.00000000e+000 5.96972978e-203] R-Squared: 0.656632624649
So we have a lot of numbers here and