text_plain_output_1.png
from keras.utils import to_categorical

from pathlib import Path

from sklearn.preprocessing import OrdinalEncoder

import numpy as np

import pandas as pd

INPUT_DIR = Path('/kaggle/input/playground-series-s3e13/')
train_data = pd.read_csv(INPUT_DIR / 'train.csv')
train_data['data_type'] = 0
train_data['prognosis'] = train_data['prognosis'].str.replace(' ', '_')
test_data = pd.read_csv(INPUT_DIR / 'test.csv')
test_data['data_type'] = 0
features = sorted(list(set(test_data.columns) - set(['id', 'data_type'])))
if INCLUDE_ORIGINAL:
    df_original = pd.read_csv('/kaggle/input/vector-borne-disease-prediction/trainn.csv')
    df_original['id'] = -1 - np.arange(len(df_original))
    df_original['prognosis'] = df_original['prognosis'].str.replace(' ', '_')
    df_original['data_type'] = 1
    train_data = pd.concat([df_original, train_data]).reset_index(drop=True)
    features = sorted(list(set(test_data.columns) - set(['id'])))

from sklearn.preprocessing import OrdinalEncoder
from keras.utils import to_categorical
enc = OrdinalEncoder()
y_enc = enc.fit_transform(train_data.filter(['prognosis']))
y = to_categorical(y_enc)
prognosis_classes = list(enc.categories_[0])
N_CLASSES = len(prognosis_classes)

feats = list(features)
X = train_data.filter(feats).values
X_train = train_data.drop('data_type', axis=1).filter(feats).values
X_data_type = train_data['data_type'].values
X_test = test_data.drop('data_type', axis=1).filter(feats).values
X_tst = test_data.filter(feats).values

n_components = 5
decomp = Decomp(n_components=n_components, method='umap', scaler_method=None)
umap_train = decomp.dimension_reduction(X_train)
umap_test = decomp.transform(X_test)

n_components = 7
decomp = Decomp(n_components=n_components, method='pca', scaler_method=None)
pca_train = decomp.dimension_reduction(X_train)
pca_test = decomp.transform(X_test)
print(f'  --> pca(n_components={n_components})')