Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to select specific column with Dimensionality Reduction pyspark

import org.apache.spark.mllib.linalg.Matrix
import org.apache.spark.mllib.linalg.SingularValueDecomposition
import org.apache.spark.mllib.linalg.Vector
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.linalg.distributed.RowMatrix

val data = 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))

val rows = sc.parallelize(data)

val mat: RowMatrix = new RowMatrix(rows)

// Compute the top 5 singular values and corresponding singular vectors.
val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(5, computeU = true)
val U: RowMatrix = svd.U  // The U factor is a RowMatrix.
val s: Vector = svd.s     // The singular values are stored in a local dense vector.
val V: Matrix = svd.V     // The V factor is a local dense matrix.
Comment

how to select specific column with Dimensionality Reduction pyspark

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 5 singular values and corresponding singular vectors.
svd = mat.computeSVD(5, computeU=True)
U = svd.U       # The U factor is a RowMatrix.
s = svd.s       # The singular values are stored in a local dense vector.
V = svd.V       # The V factor is a local dense matrix.
Comment

PREVIOUS NEXT
Code Example
Python :: save csv with today date pandas 
Python :: full_pickle 
Python :: find number of x greater than threshold in list python 
Python :: Filter xarray 
Python :: python download from digital ocean spaces boto3 
Python :: pandas impute with mean of grupby 
Python :: Iterate through string with index in python using while loop and rang 
Python :: calculate time between datetime pyspark 
Python :: "DO_NOTHING" is not defined django 
Python :: hack twitter with python 
Python :: select randomly from list in loop 
Python :: calendar range 
Python :: How to count number of distinct elements in specified axis 
Python :: accessing location of a csv cell in python 
Python :: parse tree tags 
Python :: Collecting pipnev 
Python :: jet 4 access python password 
Python :: comment arrĂȘter un jeu en appuyant sur une touche python 
Python :: arma-garch python 
Python :: hpw to create related model in django rest framework logic 
Python :: python hash md5 unicode 
Python :: python resample time series 
Python :: map dataframe parallel 
Python :: convert python to java online 
Python :: conversion of int to a specified base number 
Python :: python tuple range 
Python :: convert a column to camel case in python 
Python :: how to code discord bot 8ball python 
Python :: append to a list without intializing 
Python :: python argparse one or the other 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =