image_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']])
print(pca1.explained_variance_ratio_)
cont0_10