text_plain_output_1.png
from sklearn.model_selection import train_test_split

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('/kaggle/input/spaceship-titanic/train.csv')

data = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')

df.shape

data.shape

df.drop('PassengerId', axis=1)
df.drop('Name', axis=1, inplace=True)
data.drop('PassengerId', axis=1)
data.drop('Name', axis=1, inplace=True)

df.isnull().sum()

data.isnull().sum()

new_df = pd.concat([df, data])

new_df.shape

df_test = new_df[new_df['Transported'].isnull()]
df_train = new_df[~new_df['Transported'].isnull()]

df.drop('Cabin', axis=1, inplace=True)
data.drop('Cabin', axis=1, inplace=True)

X = df_train.drop('Transported', axis=1)
y = df_train['Transported']
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.33, shuffle=True)

from sklearn.tree import DecisionTreeClassifier
y = df['Transported']
features = ['Destination', 'CryoSleep', 'HomePlanet', 'VIP']
X = pd.get_dummies(df[features])
X_test = pd.get_dummies(data[features])
model = DecisionTreeClassifier(max_depth=7)
model.fit(X, y)