42 KiB
42 KiB
In [1]:
using CSV
using DataFrames
using Plots
using StatsPlots
using GLM
using Statistics
using Distributions
using Random
using MultivariateStats
In [2]:
μ = [0, 0]
σ = [1.0 1.0; 1.0 2.0]
dist = Distributions.MvNormal(μ, σ)
Out[2]:
In [3]:
sample = rand(dist, 100) # the random samples are close to Figure 6.14
Out[3]:
In [4]:
p = fit(PCA, sample)
Out[4]:
In [34]:
proj = projection(p) # get principle component
x = sample[1, :]
y = sample[2, :]
scatter(x, y)
first_pca = proj[:, 2] # principle components are sorted in descending order
second_pca = proj[:, 1]
plot!([-2, 2], [(2 * first_pca[1] / first_pca[2]), (-2 * first_pca[1] / first_pca[2])])
plot!([-2, 2], [(2 * second_pca[1] / second_pca[2]), (-2 * second_pca[1] / second_pca[2])])
Out[34]:
In [ ]: