<jupyter_start><jupyter_text>Implementation of Logistic Regression  Import Libraries<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import math
titanic_data = pd.read_csv("titanic.csv")
titanic_data.head(10)
print((titanic_data.info()))
print("# Total number of row and column in dataset: %s, %s" % (len(titanic_data.index), len(titanic_data.columns)))<jupyter_output># Total number of row and column in dataset: 891, 12<jupyter_text>Analyzing Data<jupyter_code>sns.countplot(x="Survived", data=titanic_data)
# 0 means passenger who had not survived
sns.countplot(x="Survived", hue="Sex", data=titanic_data)
# # O means male, female who had not survived
temp = titanic_data['Pclass'].head(10)
print(temp)

sns.countplot(x="Survived", hue="Pclass", data=titanic_data)
# O means who had not survived from which class
# # Analysis on Age column
titanic_data['Age'].plot.hist()
titanic_data['Fare'].plot.hist()
titanic_data['Fare'].plot.hist(bins=20, figsize=(10,5))
print((titanic_data.info()))
sns.countplot(x="SibSp", data=titanic_data)<jupyter_output><empty_output><jupyter_text>Data Wrangling<jupyter_code># Data Wrangling is to remove null or empty data, cleaning data set
print((titanic_data.info()))
titanic_data.isnull()
titanic_data.isnull().sum()
sns.heatmap(titanic_data.isnull(), yticklabels==False)
sns.heatmap(titanic_data.isnull(), cmap="viridis")
sns.boxplot(x="Pclass", y="Age", data=titanic_data)<jupyter_output><empty_output><jupyter_text>either drop that row or fill some value where value is null<jupyter_code>titanic_data.head(5)
titanic_data.drop("Cabin", axis=1, inplace=True)
titanic_data.head(5)
sns.heatmap(titanic_data.isnull(), yticklabels=False, cbar=False)
titanic_data.drop("Age", axis=1, inplace=True)
sns.heatmap(titanic_data.isnull(), yticklabels=False, cbar=False)
titanic_data.isnull().sum()
titanic_data.drop("Embarked", axis=1, inplace=True)
sns.heatmap(titanic_data.isnull(), yticklabels=False, cbar=False)
pd.get_dummies(titanic_data['Embarked'])
titanic_data.isnull().sum()
pd.get_dummies(titanic_data['Sex'])
pd.get_dummies(titanic_data['Sex'], drop_first=True)
sex = pd.get_dummies(titanic_data['Sex'], drop_first=True)
sex.head(5)
embark = pd.get_dummies(titanic_data['Embarked'])
embark.head(5)
embark = pd.get_dummies(titanic_data['Embarked'], drop_first=True)
embark.head(5)
pcl = pd.get_dummies(titanic_data['Pclass'], drop_first=True)
pcl.head(5)
titanic_data = pd.concat([titanic_data,sex, embark, pcl], axis=1)
titanic_data.head(5)
titanic_data.drop(['Sex', 'Embarked', 'Name', 'PassengerId', 'Ticket'], axis=True, inplace=True)
titanic_data.head(5)
titanic_data.drop(['Pclass'], axis=True, inplace=True)
titanic_data.head(5)<jupyter_output><empty_output><jupyter_text>Train and Test<jupyter_code>X = titanic_data.drop("Survived", axis=1)
y = titanic_data["Survived"]
titanic_data.head(5)
#from sklearn.cross_validation import train_test_split
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=1)
from sklearn.linear_model import LogisticRegression
logmodel = LogisticRegression()
logmodel.fit(X_train, y_train)
predictions = logmodel.predict(X_test)
from sklearn.metrics import classification_report
classification_report(y_test, predictions)
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, predictions)
from sklearn.metrics import accuracy_score
accuracy_score(y_test, predictions)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup