shahidki31 opened a new pull request #32734:
URL: https://github.com/apache/spark/pull/32734


   
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: 
https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: 
https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., 
'[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a 
faster review.
     7. If you want to add a new configuration, please read the guideline first 
for naming configurations in
        
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error message, please read the 
guideline first:
        https://spark.apache.org/error-message-guidelines.html
   -->
   
   ### What changes were proposed in this pull request?
   If the dataset contains mix of sparse and dense vectors output of PCA seems 
different. The issue here is we check only the first row's Vector type. If the 
first row is dense and rest all the row's are sparse, we compute PCA based on 
dense path. Similarly, if only first row in Sparse and rest all the rows are 
dense, we compute based on Sparse computation path.
   
   Following datasets will produce different results with PCA, even though the 
data is same, except first row type is sparse.
   ```
   val data1 = Array(
     Vectors.sparse(5, Seq((1, 1.0), (3, 7.0))),
     Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0),
     Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0)
   )
   ```
   
   ```
   +-----------------------------------------------------------+
   |pcaFeatures                                                |
   +-----------------------------------------------------------+
   |[1.6485728230883807,-4.013282700516296,-5.524543751369388] |
   |[-4.645104331781534,-1.1167972663619026,-5.524543751369387]|
   |[-6.428880535676489,-5.337951427775355,-5.524543751369389] |
   +-----------------------------------------------------------+
   
   ```
   ```
   val data1 = Array(
     Vectors.dense(0.0, 1.0, 0.0, 7.0, 0.0 ),
     Vectors.dense(2.0, 0.0, 3.0, 4.0, 5.0),
     Vectors.dense(4.0, 0.0, 0.0, 6.0, 7.0)
   )
   ```
   
   ```
   +------------------------------------------------------------+
   |pcaFeatures                                                 |
   +------------------------------------------------------------+
   |[1.6485728230883814,-4.0132827005162985,-1.0091435193998504]|
   |[-4.645104331781533,-1.1167972663619048,-1.0091435193998501]|
   |[-6.428880535676488,-5.337951427775359,-1.009143519399851]  |
   +------------------------------------------------------------+
   ```
   
   <!--
   Please clarify what changes you are proposing. The purpose of this section 
is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster 
reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class 
hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other 
DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   To fix inconsistent result if dataset contains both sparse and dense 
vectors. We need to treat the entire metrics as Sparse if all the rows are 
sparse. Otherwise we need to consider the matrix as dense.
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   Added UTs
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to