text_html_output_1.png
from sklearn.decomposition import PCA

import pandas as pd

train_data = pd.read_csv('../input/tabular-playground-series-mar-2021/train.csv')
test_data = pd.read_csv('../input/tabular-playground-series-mar-2021/test.csv')

all_data = pd.concat([train_data, test_data])
all_data

train_data.shape

all_data.drop('id', axis=1, inplace=True)
train_data.drop('id', axis=1, inplace=True)
test_data.drop('id', axis=1, inplace=True)

pca = PCA(n_components=1)
cont1_2 = pca.fit_transform(all_data[['cont1', 'cont2']])
cont1_2

all_data['cont1_2'] = cont1_2
all_data.drop('cont1', axis=1, inplace=True)
all_data.drop('cont2', axis=1, inplace=True)

pca1 = PCA(n_components=1)
cont0_10 = pca1.fit_transform(all_data[['cont0', 'cont10']])
cont0_10

all_data['cont0_10'] = cont0_10
all_data.drop('cont10', axis=1, inplace=True)
all_data.drop('cont0', axis=1, inplace=True)

all_data = all_data[['cat0', 'cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7', 'cat8', 'cat9', 'cat10', 'cat11', 'cat12', 'cat13', 'cat14', 'cat15', 'cat16', 'cat17', 'cat18', 'cont3', 'cont4', 'cont5', 'cont6', 'cont7', 'cont8', 'cont9', 'cont1_2', 'cont0_10', 'target']]

train_data = all_data.iloc[0:300000, :]
test_data = all_data.iloc[300000:, :].drop(['target'], axis=1)

all_data.head()