Skip to main content

Principal component analysis in Gurobi as a non convex problem. Inaccurate solution

Answered

Comments

1 comment

  • Official comment
    Juan Orozco
    Gurobi Staff Gurobi Staff

    Dear Álvaro,

    Recall that PCA is not scale invariant. It's very important to check whether a specific implementation centers and/or scales the data matrix before finding the principal components. As stated in Scikit-learn's website: "The input data is centered but not scaled for each feature before applying the SVD (Singular Value Decomposition)."

    Therefore, you must subtract the sample average from each column as follows:

    x = x - np.mean(x, 0)

    Having this change in place, you'll see that the optimal solution found by Gurobi for the first principal component agrees with Scikit-learn.

Please sign in to leave a comment.