First Attempt

import pandas # Read in data file titanic = pandas.read_csv(‘../input/train.csv’) # Fill in missing ages with median titanic[‘Age’] = titanic [‘Age’].fillna(titanic[‘Age’].median()) # Machine learning algorithms can only make sense of numeric data. # Replace sex strings with numeric 0 for male and 1 for female titanic.loc[titanic[‘Sex’] == ‘male’,’Sex’] = 0 titanic.loc[titanic[‘Sex’] == ‘female’,’Sex’] = 1 # Assumed nan Embarked values to be S (the most common) titanic[‘Embarked’] = titanic[‘Embarked’].fillna(‘S’) # Replace embarked values S(0), C(1), Q(2) titanic.loc[titanic[‘Embarked’] == ‘S’,’Embarked’] = 0 titanic.loc[titanic[‘Embarked’] == ‘C’,’Embarked’] = 1 titanic.loc[titanic[‘Embarked’] == ‘Q’,’Embarked’] = 2 # Import the linear regression class from sklearn.linear_model import LogisticRegression #Sklearn also has a helper that makes it easy to do cross validation from sklearn import cross_validation # The columns we’ll use to predict the target predictors = [‘Pclass’,…

Link to Full Article: First Attempt

Pin It on Pinterest

Share This

Join Our Newsletter

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

You have Successfully Subscribed!