Logistic Model using scikit-learn

import numpy as np import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn import cross_validation # Initialize our algorithm alg = LogisticRegression(random_state=1) # Print you can execute arbitrary python code train = pd.read_csv(“../input/train.csv”, dtype={“Age”: np.float64}, ) test = pd.read_csv(“../input/test.csv”, dtype={“Age”: np.float64}, ) # Fix train data train[“Age”] = train[“Age”].fillna(train[“Age”].median()) train.loc[train[“Sex”] == “male”, “Sex”] = 0 train.loc[train[“Sex”] == “female”, “Sex”] = 1 train[“Embarked”] = train[“Embarked”].fillna(“S”) train.loc[train[“Embarked”] == “S”, “Embarked”] = 0 train.loc[train[“Embarked”] == “C”, “Embarked”] = 1 train.loc[train[“Embarked”] == “Q”, “Embarked”] = 2 train[“Fare”] = train[“Fare”].fillna(train[“Fare”].median()) # Fix test data test[“Age”] = test[“Age”].fillna(train[“Age”].median()) test.loc[test[“Sex”] == “male”, “Sex”] = 0 test.loc[test[“Sex”] == “female”, “Sex”] = 1 test[“Embarked”] = test[“Embarked”].fillna(“S”) test.loc[test[“Embarked”] == “S”, “Embarked”] = 0 test.loc[test[“Embarked”] == “C”, “Embarked”] = 1 test.loc[test[“Embarked”] == “Q”, “Embarked”] = 2 test[“Fare”] = test[“Fare”].fillna(train[“Fare”].median()) #…


Link to Full Article: Logistic Model using scikit-learn

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!