Advertisement
jpyne17

i2s-summer-school

Aug 21st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # model formula
  2. # here the ~ sign is an = sign, and the features of our dataset
  3. # are written as a formula to predict survived. The C() lets our
  4. # regression know that those variables are categorical.
  5. # Ref: http://patsy.readthedocs.org/en/latest/formulas.html
  6. formula = 'Survived ~ C(Pclass) + C(Sex) + Age + SibSp  + C(Embarked)'
  7. # create a results dictionary to hold our regression results for easy analysis later        
  8. results = {}
  9.  
  10. # create a regression friendly dataframe using patsy's dmatrices function
  11. y,x = dmatrices(formula, data=df, return_type='dataframe')
  12.  
  13. # instantiate our model
  14. model = sm.Logit(y,x)
  15.  
  16. # fit our model to the training data
  17. res = model.fit()
  18.  
  19. # save the result for outputing predictions later
  20. results['Logit'] = [res, formula]
  21. res.summary()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement