Why are linear discriminant analysis in SPSS and Python not giving me the same results for coefficients?

111 views Asked by At

Although the data I'm feeding into both SPSS and Python is identical, I'm getting different scores for eigenvalues and canonical discriminant function coefficients while tests of equality of group means work accurately. Could you please offer a solution? I'm sharing the canonical discriminant function coefficients I got, SPSS syntax I ran and Python code I used below.

DATASET ACTIVATE DataSet1.
DISCRIMINANT
  /GROUPS=Gender(0 1)
  /VARIABLES=Height Width Div_Depth
  /ANALYSIS ALL
  /SAVE=CLASS PROBS 
  /PRIORS EQUAL 
  /STATISTICS=MEAN STDDEV UNIVF BOXM COEFF RAW CORR TABLE CROSSVALID 
  /CLASSIFY=NONMISSING POOLED.

SPSS Output:

  • Height 8.376
  • Width -.564
  • Div_Depth -6.201
  • (Constant) -29.031
import pandas as pd
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
data = pd.read_excel("data.xlsx")
X = data[["Height", "Width", "Div_Depth"]]
y = data["Gender"]
lda = LDA()
lda_model = lda.fit(X, y)
print("Canonical Discriminant Function Coefficients:", lda.coef_)
print("Canonical Discriminant Function Constant:", lda.intercept_)

Python Output:

  • Canonical Discriminant Function Coefficients: [[-101.85246698 6.86029024 75.4023029 ]]
  • Canonical Discriminant Function Constant: [353.00578148]

You can find the data sample I've used at https://wetransfer.com/downloads/d8e2252cf4878dad9ec2b5dea54d45d620230926202231/f8564eb573c9e4b5e2f70da3b2d909a920230926202259/8e586b?trk=TRN_TDL_01&utm_campaign=TRN_TDL_01&utm_medium=email&utm_source=sendgrid

0

There are 0 answers