<jupyter_start><jupyter_text>Decision_tree<jupyter_code>import numpy as np
import pandas as pd
df1 = pd.read_csv("titanic.csv")
df1

df1.drop(['PassengerId','Name','SibSp','Parch','Ticket','Cabin','Embarked'],axis='columns',inplace=True)

#inplace = true means the data is changed permenantly so you dont have to save it in a new dataframe
df1.head()
X = df1.drop(['Survived'],axis='columns')
X
y= df1['Survived']
y
#fill the NaN with the mean of the Age column

import math
X.Age = X.Age.fillna(X.Age.mean())
X
#all columns has to be in numbers so change the Sex column using map 
X.Sex = X.Sex.map({'male': 1, 'female': 2})
X
#MODEL 

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2)
from sklearn import tree
model = tree.DecisionTreeClassifier()
model.fit(X_train,y_train)
y_predicted = model.predict(X_test)
y_predicted
model.score(X_test,y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13130252100840337, 'fraction_numerical': 0.01050420168067227, 'mean_word_length': 6.685483870967742, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '340947', 'license': 'MIT', 'n_tokens_mistral': 375, 'n_tokens_neox': 360, 'n_words': 91, 'path': 'Decision_tree_titanic_dataset.ipynb', 'repo_name': 'SandhiyaRa/Decision-Tree', 'size': '952'}