<jupyter_start><jupyter_text>Data Collection and Preprocessing<jupyter_code>titanic_data=pd.read_csv("train.csv")
titanic_data.head()
#no.of rows and columns
titanic_data.shape
titanic_data.info()
#check the no.of missing values in each columns
titanic_data.isnull().sum()
#handling missing values
#drop cabin column from dataframe
titanic_data=titanic_data.drop(columns='Cabin')
titanic_data.shape
#Replacing the missing values in age column by mean of age
titanic_data['Age'].fillna(titanic_data['Age'].mean(),inplace=True)
titanic_data.isnull().sum()
#finding the mode value of Embarked Column
titanic_data['Embarked'].mode()
titanic_data['Embarked'].mode()[0]
#replacing the missing values in embarked column with mode value
titanic_data['Embarked'].fillna(titanic_data['Embarked'].mode()[0],inplace=True)
#Checking missing values after preprocessing
titanic_data.isnull().sum()<jupyter_output><empty_output><jupyter_text>Data Analysis<jupyter_code>#getting some statistical measures about data
titanic_data.describe()
#finding the number of people survived and not survived
titanic_data['Survived'].value_counts()<jupyter_output><empty_output><jupyter_text>Data Visualisation<jupyter_code>sns.set()
#making a count plot for survived column
sns.countplot("Survived",data=titanic_data)
titanic_data['Survived'].plot.hist()
sns.countplot("Sex",data=titanic_data)
#no.of survived on based on gender

sns.countplot('Sex',hue='Survived',data=titanic_data)
sns.countplot("Pclass",data=titanic_data)
sns.countplot("Pclass",hue='Survived',data=titanic_data)
#Encoding categorical columns
titanic_data['Sex'].value_counts()
titanic_data['Embarked'].value_counts()
#converting categorical columns into numerical 

titanic_data.replace({'Sex':{'male':0,'female':1},"Embarked":{"S":0,"C":1,"Q":2}},inplace=True )
titanic_data.head()<jupyter_output><empty_output><jupyter_text>Separating features and target<jupyter_code>X=titanic_data.drop(['Name','PassengerId','Ticket','Survived'],axis=1)
Y=titanic_data['Survived']
print(X)
print(Y)
#Splitting the data into training and testdata
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.2,random_state=2)
print(X.shape,X_train.shape,X_test.shape)
print(Y.shape,Y_train.shape,Y_test.shape)<jupyter_output>(891,) (712,) (179,)<jupyter_text>Model training<jupyter_code>#Logistic regression
model=LogisticRegression()
#training the logistic regression model with training data
model.fit(X_train,Y_train)
#Accuracy Score
#accuracy on training model
X_train_prediction=model.predict(X_train)
X_train_prediction
training_data_accuracy=accuracy_score(Y_train,X_train_prediction)
print("Accuracy score of training data:",training_data_accuracy)
#accuracy on test data 
X_test_prediction=model.predict(X_test)
X_test_prediction
testing_data_accuracy=accuracy_score(Y_test,X_test_prediction)
print("Accuracy score of testing data:",testing_data_accuracy)
X
Y
#Making a predictive system
print("Enter the values:Pclass,Sex,Age,SibSp,Parch,Fare,Embarked ")
s=input().split()
t=tuple([float(i) for i in s])
input_data=t

#changing input data to numpy array
input_data_as_numpy_array=np.asarray(input_data)
print(input_data_as_numpy_array)

#reshaping the array as we are preicting for one instance
input_data_reshaped=input_data_as_numpy_array.reshape(1,-1)
print(input_data_reshaped)

prediction=model.predict(input_data_reshaped)
print("prediction is ",prediction)

if prediction[0]==0:
    print("The passenger was not survived")
else:
    print("The passenger was survived")
X,Y
#Testing the test data set
df=pd.read_csv("test.csv")
df.head()
df.isnull().sum()
df=df.drop('Cabin',axis=1)
df.shape
df.isnull().sum()
df['Age'].fillna(df['Age'].mean(),inplace=True)
df.isnull().sum()
df['Fare'].fillna(df['Fare'].mean(),inplace=True)
df
df.replace({'Sex':{'male':0,'female':1},"Embarked":{"S":0,"C":1,"Q":2}},inplace=True )
df.head()
U=df.drop(['Name','PassengerId','Ticket'],axis=1)
U.head()
X.head()
k=model.predict(U)
df1=pd.DataFrame(df['PassengerId'])
df1
df1['Survived']=k
df1
df1.to_csv("predictions.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14411764705882352, 'fraction_numerical': 0.008823529411764706, 'mean_word_length': 10.727011494252874, 'pattern_counts': {'":': 8, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '635773', 'license': 'MIT', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1502, 'n_words': 253, 'path': 'Titanic Project.ipynb', 'repo_name': 'katakamrakesh/Titanic-Project', 'size': '4080'}