Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Principal component analysis (PCA)

from pyspark.mllib.linalg import Vectors
from pyspark.mllib.linalg.distributed import RowMatrix

rows = sc.parallelize([
    Vectors.sparse(5, {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)
])

mat = RowMatrix(rows)
# Compute the top 4 principal components.
# Principal components are stored in a local dense matrix.
pc = mat.computePrincipalComponents(4)

# Project the rows to the linear space spanned by the top 4 principal components.
projected = mat.multiply(pc)
Comment

Principal component analysis (PCA)

from pyspark.mllib.linalg import Vectors
from pyspark.mllib.linalg.distributed import RowMatrix

rows = sc.parallelize([
    Vectors.sparse(5, {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)
])

mat = RowMatrix(rows)
# Compute the top 4 principal components.
# Principal components are stored in a local dense matrix.
pc = mat.computePrincipalComponents(4)

# Project the rows to the linear space spanned by the top 4 principal components.
projected = mat.multiply(pc)
Comment

PREVIOUS NEXT
Code Example
Python :: try except in list comprehension 
Python :: Routes In Django 
Python :: index in python 
Python :: python functools 
Python :: how to append to a string in python 
Python :: pandas dummy classification data 
Python :: immutability in python 
Python :: function composition python 
Python :: all string methods in python 
Python :: python how to run code in ssh 
Python :: create a new column in pandas dataframe based on the existing columns 
Python :: python list clear vs del 
Python :: swap list 
Python :: convert time 
Python :: whitespace delimiter python 
Python :: csv to excel python 
Python :: python pandas merge dataframe 
Python :: pk django 
Python :: set() python 
Python :: import from parent module package python 
Python :: how to make a letter capital in python 
Python :: python how to loop 
Python :: how to console log in django heroku 
Python :: python list of deeper paths 
Python :: python str and repr 
Python :: Add one to a column pands 
Python :: for 2d data compute standard deviation at each x 
Python :: calc investiment money puthon 
Python :: #finding the differences between setA and SetB: 
Python :: numpy create array with infinities 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =