0
$\begingroup$

I have trained a VAE with jpg images. My latent space dimension has 768 features and when plotting the latent space it looks like this: latent space only on two dimensions

However, when I use the scikit learn tool LDA (Linear Discriminant Analysis) to reduce to two dimensions it looks like this:

LDA reduction

This is the code:

features,sigma, mean = encoder.predict(x_train)
#Features have 768 dimensions
lda =LinearDiscriminantAnalysis(
        n_components=2)
labels = y_train
digit_features_lda=lda.fit_transform(features,labels)
#digit_features_lda are two dimensional

I dont have the labels for the test data, I can encode to 768 dimensions but LDA requires labels to reduce to two dimensions.

$\endgroup$
3
  • $\begingroup$ How did you reduce/project the dimeansion of 768 to create the first plot (which is 2D)? $\endgroup$
    – Broele
    Mar 23, 2023 at 15:29
  • $\begingroup$ Hi @Dude Rar, and welcome to AI Stack Exchange! If possible, please edit this question to include a specific question in the body of your post. $\endgroup$
    – DeepQZero
    Mar 23, 2023 at 15:53
  • $\begingroup$ @Broele I only took two dimensions. i.e. encoder[0] and encoder[1]. $\endgroup$
    – Dude Rar
    Mar 24, 2023 at 0:56

1 Answer 1

0
$\begingroup$

LinearDiscriminantAnalysis is an scikit-learn transformer. These typically have to steps:

  1. fit(X,y): This step is used to train the transformation. Depending on the transformer, the target variable / the labels might be used, here. As input, one uses the training data with labels. In case of LinearDiscriminantAnalysis, you could understand the fit method as finding a transformation of the features X, that allows to separate the classes (given by y) best. To find the transformation, the algorithm needs to know y.
  2. transform(X): This step applys the trained transformation to input samples. This can be training data, testing data or some other data (with the correct dimension). Since the transformation is already trained, it does not need to know the labels anymore.

Having that said, just call

digit_features_lda_test = lda.transform(test_features)
$\endgroup$
2
  • $\begingroup$ how can I save this lda transform in a variable? lets say I want to share to test my model $\endgroup$
    – Dude Rar
    Mar 30, 2023 at 14:47
  • $\begingroup$ This should be a question on its own $\endgroup$
    – Broele
    Mar 31, 2023 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .