text_plain_output_1.png image_output_1.png
from sklearn import preprocessing

import pandas as pd

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

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

dtrain.isna().sum()

dtest.isna().sum()

le = preprocessing.LabelEncoder()
dtrain['VIP'] = le.fit_transform(dtrain['VIP'])
oe = preprocessing.OneHotEncoder(handle_unknown='ignore')
encoder_home = pd.DataFrame(oe.fit_transform(dtrain[['HomePlanet']]).toarray())
encoder_dest = pd.DataFrame(oe.fit_transform(dtrain[['Destination']]).toarray())
dtrain['Earth'] = encoder_home[0]
dtrain['Europa'] = encoder_home[1]
dtrain['Mars'] = encoder_home[2]
dtrain['CANCRI'] = encoder_dest[0]
dtrain['PSO'] = encoder_dest[1]
dtrain['TRAPPIST'] = encoder_dest[2]

le = preprocessing.LabelEncoder()
dtest['VIP'] = le.fit_transform(dtest['VIP'])
oe = preprocessing.OneHotEncoder(handle_unknown='ignore')
encoder_home = pd.DataFrame(oe.fit_transform(dtest[['HomePlanet']]).toarray())
encoder_dest = pd.DataFrame(oe.fit_transform(dtest[['Destination']]).toarray())
dtest['Earth'] = encoder_home[0]
dtest['Europa'] = encoder_home[1]
dtest['Mars'] = encoder_home[2]
dtest['CANCRI'] = encoder_dest[0]
dtest['PSO'] = encoder_dest[1]
dtest['TRAPPIST'] = encoder_dest[2]
dtest.head()