# Spaceship Titanic classification model

Using the Kaggle Spaceship Titanic [dataset](https://www.kaggle.com/competitions/spaceship-titanic), I created a machine learning model in python to predict which passengers in the data would be transported to an alternate dimension.

Check out the Kaggle [notebook](https://www.kaggle.com/code/glenn23/spaceship-titanic-model)

### **Data Exploration**

The first step was loading and performing some data exploration

A pair plot is a helpful visual to spot correlations.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703708601897/91783689-a48f-459e-b154-1d5cd5772f46.png align="center")

Here is a visual of the age of those transported

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703708798298/0f111bb0-aea2-4e67-b081-c1aba54e753a.png align="center")

During the data exploration I used the `get_dummies` function on the 'HomePlanet' and 'Destination' columns. I also performed other methods to clean and transform the data.

```python
df_data_final = pd.get_dummies(df_data_final, columns=['HomePlanet', 'Destination'], drop_first=False)
```

I created a tableau [dashboard](https://public.tableau.com/app/profile/donald.tucker4155/viz/SpaceshipTitanic_16882551562560/PassengerDashboard) to help visualize the data. This wasn't necessary but helped me see and interact with the data.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703709015618/98b00561-7981-4ea1-9041-56491114777b.png align="center")

### Creating the model

The target variable is the 'Transported' column, the rest of the columns are the features.

```python
# Define the y (target) variable.
y = df_data_final['Transported']

# Define the X (predictor) variables.
X = df_data_final.drop(['Transported'], axis = 1)
```

### Results

Random Forest Model Accuracy: 0.781048758049678

XGBoost Model Accuracy: 0.7828886844526219

The XGBoost model performed slightly better on the training data.

If you are interested, the Kaggle notebook can be found [here](https://www.kaggle.com/code/glenn23/spaceship-titanic-model)
