<jupyter_start><jupyter_text>Logistic Regression<jupyter_code>#Importing packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
%matplotlib inline
dataset=pd.read_csv('C:/Users/Bharathi/Downloads/titanic_train.csv')
dataset.head()
dataset.shape
dataset.info()
dataset.isnull()
sb.heatmap(dataset.isnull())
sb.countplot(x='Survived',data=dataset)
sb.countplot(x='Survived',hue='Sex',data=dataset)
sb.countplot(x='Survived',hue='Pclass',data=dataset)
plt.figure(figsize=(12,7))
sb.boxplot(x='Pclass',y='Age',data=dataset,palette='winter')
def impute_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
dataset['Age']=dataset[['Age','Pclass']].apply(impute_age,axis=1)
sb.heatmap(dataset.isnull())
dataset.drop('Cabin',axis=1,inplace=True)
dataset.info()
sex=pd.get_dummies(dataset['Sex'],drop_first=True)
embark=pd.get_dummies(dataset['Embarked'],drop_first=True)
dataset.drop(['PassengerId','Sex','Embarked','Name','Ticket'],axis=1,inplace=True)
dataset=pd.concat([dataset,sex,embark],axis=1)
dataset.head()
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(dataset.drop('Survived',axis=1),
                                        dataset['Survived'],test_size=0.20,
                                        random_state=101)
from sklearn.linear_model import LogisticRegression
logmodel=LogisticRegression()
logmodel.fit(X_train,y_train)
predictions=logmodel.predict(X_test)
print(predictions[5])
y_test.head(5)



logmodel.score(X_test,y_test)
dataset.head()
dataset.tail()
dataset['Age']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1488294314381271, 'fraction_numerical': 0.014492753623188406, 'mean_word_length': 5.0641891891891895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '657213', 'license': 'MIT', 'n_tokens_mistral': 660, 'n_tokens_neox': 633, 'n_words': 81, 'path': 'Logistic Regression using ML(titanic).ipynb', 'repo_name': 'bharathiyakshi1985/Titanic_study', 'size': '1794'}