Skip to main content

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

Answered

Comments

2 comments

  • 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.

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.

Post is closed for comments.