<jupyter_start><jupyter_text>EDA with Python using Logistic Regression  Import Libraries<jupyter_code>import pandas as pd 
import numpy as np
import seaborn as sns
import matplotlib as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>The Data<jupyter_code>train = pd.read_csv("titanic_train.csv")
train.head()<jupyter_output><empty_output><jupyter_text>EDA  Missing Data<jupyter_code>train.isnull()<jupyter_output><empty_output><jupyter_text>Using heatmap to visualize the null val<jupyter_code>sns.heatmap(train.isnull(), yticklabels=False, cbar= False, cmap="viridis")
sns.set_style('whitegrid')
sns.countplot(x='Survived', hue="Sex",data=train, palette="RdBu_r" )
sns.countplot(x="Survived", data= train)
sns.countplot(x="Survived", hue="Pclass", data= train)<jupyter_output><empty_output><jupyter_text>to check the avg age of ppl that died<jupyter_code>sns.distplot(train["Age"].dropna(), kde=False, color="darkred", bins=40)
sns.countplot(x="SibSp", data=train) #sibling n spouse count in  a family
train["Fare"].hist(color="red", bins=40, figsize=(8,4))<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code>#plt.figure(figsize=(12, 7))
sns.boxplot(x="Pclass", y="Age", data= train)<jupyter_output><empty_output><jupyter_text>we can see wealthier passenger cls1 tend to be older . well use avg age value ot impute based on pclas age<jupyter_code>#to remove the null elements
def input_age(cols):
    Age=cols[0]
    Pclass= cols[1]
    
    if pd.isnull(Age):
        
        if Pclass ==1:
            return 37
        elif Pclass ==2:
            return 29
        else:
            return 24
        
    else: 
        return Age
train["Age"]= train[['Age', 'Pclass']].apply(input_age, axis=1)
sns.heatmap(train.isnull(), yticklabels= False, cbar= False, cmap= 'viridis')
#drop the cabin col
train.drop('Cabin', axis=1, inplace= True)
train.head()
train.dropna(inplace= True)<jupyter_output><empty_output><jupyter_text>Converting Categorical Features<jupyter_code>train.info()
#get_dummies-> converts info in that many dummies in drop the col which r not rqd 
pd.get_dummies(train['Embarked'], drop_first= True).head()
sex= pd.get_dummies(train["Sex"], drop_first= True)
embark= pd.get_dummies(train["Embarked"], drop_first= True)
train.drop(["Sex", "Embarked", "Name", "Ticket"], axis=1, inplace=True)
train.head()
train = pd.concat([train, sex, embark], axis=1)
train.head()<jupyter_output><empty_output><jupyter_text>Building Logistic Regression Model Train Test Split<jupyter_code>train.drop("Survived", axis=1).head()
train["Survived"].head()
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(train.drop("Survived", axis=1), 
                                                  train["Survived"], test_size= 0.30,
                                                  random_state= 101)<jupyter_output><empty_output><jupyter_text>Training and Predicting<jupyter_code>from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(x_train, y_train)
prediction = model.predict(x_test)
from sklearn.metrics import confusion_matrix
accuracy = confusion_matrix(y_test, prediction)
accuracy
from sklearn.metrics import accuracy_score
accuracy= accuracy_score(y_test, prediction)
accuracy
prediction<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12694145758661887, 'fraction_numerical': 0.009557945041816009, 'mean_word_length': 5.605522682445759, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '363849', 'license': 'MIT', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1173, 'n_words': 241, 'path': 'Exploratory Data Analysis(EDA).ipynb', 'repo_name': 'ArpitaChatterjee/LogisticReg-Titanic-Data-Analysis', 'size': '3348'}