<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from google.colab import files
# dataset=pd.read_csv('Data.csv')
# uploaded = files.upload()
data=pd.read_csv('train.csv')
test=pd.read_csv('test.csv')
test_ids = test["PassengerId"]
# data.head()
test.head()
# This step will delete all the irrelevant data columns from the set. For e.g. ["Ticket","Cabin","Name","PassengerId"]
# It will also replace the numerical data with a median value
def clean(data):
  data=data.drop(["Ticket","Cabin","Name","PassengerId"],axis=1)
  cols=["SibSp","Parch","Fare","Age"]
  for i in cols:
    data[i].fillna(data[i].median(),inplace=True)
  data.Embarked.fillna("U",inplace=True)
  return data

data=clean(data)
test=clean(test)
# This code will change the data from string into numbers. For e.g. male is 1 and female is 0 under Column "Sex".

from sklearn import preprocessing
le=preprocessing.LabelEncoder()

cols=["Sex","Embarked"]

for col in cols:
  data[col]=le.fit_transform(data[col])
  
  test[col]=le.transform(test[col])
  print(le.classes_)

# data.head(5)
test.head(5)
### 3. Splitting the training set data into test and train 

from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

y=data["Survived"]
X=data.drop("Survived",axis=1)

X_train, X_val,y_train,y_val=train_test_split(X,y,test_size=0.2,random_state=42)
clf=LogisticRegression(random_state=0,max_iter=1000).fit(X_train,y_train)
 predictions=clf.predict(X_val)
 from sklearn.metrics import accuracy_score
 accuracy_score(y_val,predictions)
submission_preds=clf.predict(test)
df = pd.DataFrame({"PassengerId": test_ids.values,
                   "Survived": submission_preds,
                  })
df.to_csv("submission.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13752030319436925, 'fraction_numerical': 0.008662696264212236, 'mean_word_length': 5.895522388059701, 'pattern_counts': {'":': 2, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '658932', 'license': 'Unlicense', 'n_tokens_mistral': 674, 'n_tokens_neox': 653, 'n_words': 139, 'path': 'Titanic_Kaggle_V1.ipynb', 'repo_name': 'haseebkhan611/HDL-Bits-Solutions', 'size': '1847'}