Simple Logistic Regression Model

import numpy as np from pandas import Series, DataFrame import pandas as pd from sklearn.grid_search import GridSearchCV from sklearn.linear_model import LogisticRegression def has_title(name): for s in [‘Mr.’, ‘Mrs.’, ‘Miss.’, ‘Dr.’, ‘Sir.’]: if name.find(s) >= 0: return True return False def munge(df): # Pclass for i in range(3): cls_fn = lambda x: 0.5 if x == i + 1 else -0.5 df[‘C%d’ % i] = df[‘Pclass’].map(cls_fn) # Sex => Gender gender_fn = lambda x: -0.5 if x == ‘male’ else 0.5 df[‘Gender’] = df[‘Sex’].map(gender_fn) # Name => Title title_fn = lambda x: 0.5 if has_title(x) else -0.5 title_col = df[‘Name’].map(title_fn) title_col.name = ‘Title’ dfn = pd.concat([df, title_col], axis=1) # Embarked s3fa_col = (dfn.Pclass == 3).mul(dfn.Sex == ‘female’).mul(dfn.Embarked == ‘S’).mul(dfn.Title > 0) s3fa_fn = lambda x: 0.5 if x else -0.5 s3fa_col…


Link to Full Article: Simple Logistic Regression Model

Pin It on Pinterest

Share This

Join Our Newsletter

Sign up to our mailing list to receive the latest news and updates about homeAI.info and the Informed.AI Network of AI related websites which includes Events.AI, Neurons.AI, Awards.AI, and Vocation.AI

You have Successfully Subscribed!