Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # model formula
- # here the ~ sign is an = sign, and the features of our dataset
- # are written as a formula to predict survived. The C() lets our
- # regression know that those variables are categorical.
- # Ref: http://patsy.readthedocs.org/en/latest/formulas.html
- formula = 'Survived ~ C(Pclass) + C(Sex) + Age + SibSp + C(Embarked)'
- # create a results dictionary to hold our regression results for easy analysis later
- results = {}
- # create a regression friendly dataframe using patsy's dmatrices function
- y,x = dmatrices(formula, data=df, return_type='dataframe')
- # instantiate our model
- model = sm.Logit(y,x)
- # fit our model to the training data
- res = model.fit()
- # save the result for outputing predictions later
- results['Logit'] = [res, formula]
- res.summary()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement