Package: embedding-tool
Embedding ToolAn embedding toolkit that can perform multiple embedding process which are low-dimensional embedding (dimension reduction), categorical variable embedding, and financial time-series embedding.Installpip install embedding-toolfromembedding_tool.coreimport*How to useDimension Reduction:dimensionReducerclassThe function performs dimensionality reduction, pre-processing the data and comparing the reconstruction error via PCA and autoencoder.Input data:The input matrix has a size of 863 $\times$ 768.print("Data's size: ",testing_data.shape)Data's size:  (863, 768)Performing dimension reduction:we will reduce the number of dimension from 768 to 2. The learning rate of 0.002 will be use for the ADAM optimizer for the autoencoder model fitting.dim_reducer=dimensionReducer(testing_data,2,0.002)dim_reducer.fit()Calculating the MSE of the reconstructed vectorsdim_reducer.rmse_result<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>PCA1AE2AEMSE0.7401220.7412650.65168dim_reducer.rmse_result.T.sort_values('MSE').head(1).values[0][0]0.6516801665399286Here we can see that the two-layers autoencoder has the best performance with the lowest MSE of 0.64.Observing the loss for each epoch:If we see that the MSE doesn't converge fast enough, we could adjust the learning rate parameter. The default is 0.002. Try increase it to 0.005 if it doesn't converge or decrease to 0.001 if it converges way too fast and oscillating.dim_reducer.plot_autoencoder_performance()Result (Reduced Dimension Output):There are three outputs from three different methods, which are PCA, 1-layer AE, and 2-layers AE.### Embedding from PCAdim_reducer.dfLowDimPCA.head()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>010-16.078718-6.7014811-8.8581509.35420424.305739-0.4647073-11.514311-0.68746141.2120066.537965### Embedding from 1-layer autoencoderdim_reducer.dfLowDim1AE.head()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>010-6.1780974.73462612.0753335.52911120.953502-1.6677763-2.4881554.00196043.1836540.589496### Embedding from 2-layers autoencoderdim_reducer.dfLowDim2AE.head()<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}</style>01032.62206654.652271135.64981140.493984215.3142945.869064319.66760337.821194436.18321225.429262Plotting the embedding### Embedding from 2-layers autoencoderplot_output(dim_reducer.dfLowDim2AE)### Embedding from 1-layer autoencoderplot_output(dim_reducer.dfLowDim1AE)Reference:https://towardsdatascience.com/dimensionality-reduction-pca-versus-autoencoders-338fcaf3297dhttps://towardsdatascience.com/autoencoders-vs-pca-when-to-use-which-73de063f5d7