GithubHelp home page GithubHelp logo

wildart / dimensionalityreduction.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juliastats/dimensionalityreduction.jl

0.0 2.0 1.0 271 KB

Methods for dimensionality reduction

License: Other

Julia 100.00%

dimensionalityreduction.jl's Introduction

DimensionalityReduction.jl

Algorithms

  • Principal Component Analysis (PCA)

PCA Usage

using DimensionalityReduction

# simulate 100 random observations
# rotate and scale as well
X = randn(100,2) * [0.8 0.7; 0.9 0.5]
Xpca = pca(X)

Rows of X each represent a data point (i.e., a different repetition of the experiment), and columns of X represent the different variables measured.

Attributes:

Xpca.rotation                # principal components
Xpca.scores                  # rotated X
Xpca.standard_deviations     # square roots of the eigenvalues
Xpca.proportion_of_variance  # fraction of variance brought by each principal component
Xpca.cumulative_variance     # cumulative proportion of variance

By default, pca() uses SVD decomposition. Alternatively, pcaeig(X) will calculate directly the eigenvectors of the covariance matrix.

pca() centers and re-scales input data by default. This is controlled by the center and scale keyword arguments:

pca(X::Matrix ; center::Bool, scale::Bool)

Centering is done by subtracting the mean, and scaling by normalizing each variable by its standard deviation.

If scale is true (default), then the principal components of the data are also scaled back to the original space and saved to Xpca.rotation

To overlay the principal components on top of the data with PyPlot

using PyPlot
plot( X[:,1], X[:,2], "r." )  # point cloud

# get data center
ctr = mean( X, 1 )

# plot principal components as lines
#  weight by their standard deviation
PCs = Xpca.rotation
for v=1:2
	weight = Xpca.standard_deviations[v]
	plot( ctr[1] + weight * [0, PCs[1,v]], 
		  ctr[2] + weight * [0, PCs[2,v]],
		  linewidth = 2)
end

To make a biplot with PyPlot

using PyPlot
scores = Xpca.scores[:,1:2]
plot( scores[:,1], scores[:,2], "r." )

To make a biplot with Gadfly:

using Gadfly
scores = Xpca.scores[:,1:2]
pl = plot(x=scores[:,1],y=scores[:,2], Geom.point)
draw(PNG("pca.png", 6inch, 6inch), pl)

Starting from a DataFrame:

using RDatasets
iris = data("datasets", "iris")
iris = convert(Array,DataArray(iris[:,1:4]))
Xpca = pca(iris)

ICA Usage

ICA has been deprecated.

t-SNE Usage

t-SNE has been deprecated.

NMF

NMF has been moved into a separate package.

dimensionalityreduction.jl's People

Contributors

andreasnoack avatar bloody76 avatar cbecker avatar csaid avatar delafont avatar johnmyleswhite avatar lindahua avatar simonster avatar

Watchers

 avatar  avatar

Forkers

zeta1999

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.