0

I tried to use LDA and find a 3-channel output. But its output has just 2 channels.

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA

x = []
y = []
for i in range(len(img)):
    for j in range(len(img[0])):
        x.append([i,i,j,j])
        y.append(img[i][j])
y = np.array(y)
x = np.array(x)
y.shape,x.shape
lad = out = _ = ''
lda = LDA(n_components=3)
out = lda.fit(x, y).transform(x)
print(out.shape,y.shape,x.shape)

I used [i, i, j, j] because LDA asked me to have x with more features.

and printed output is: ((392960, 2), (392960,), (392960, 4)) but for out.shape I seek (392960,3)

Can anyone help me with this, please?

1 Answers1

0

The number of components in LinearDiscriminantAnalysis is always lower than the number of classes as it projects the data into an affine subspace of dimension at most the number of classes minus 1. It looks like your y has 3 classes.

Sanjar Adilov
  • 1,039
  • 7
  • 15
  • 1
    Thank you, Sanjar Adilov, but no, my data had about 250 different classes, but I decided to use another algorithm in the end. Maybe you guessed that from x.shape, but it is just each node's x,y dimension, but I used them two times to avoid limitations based on LDA documentation. BTW, Thank you very much. – aliiiiiiiiiiiiiiiiiiiii Apr 23 '22 at 17:50