Created
January 22, 2019 09:46
-
-
Save regonn/dd88fe937450e8edde61ea2e3478251b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MultivariateStats # PCA | |
using PlotlyJS # データプロット用 Plotly.jl ではなく js実装を呼ぶ PlotlyJS.jl こちらの方がメンテされている | |
using CSV, DataFrames # CSV と DataFrames が扱えるように | |
df = CSV.File("SF.csv") |> DataFrame | |
reciprocals = 1 ./ Matrix(df[:,2:8]) # 逆数にして1番目の性格の値が大きくなるように | |
top5 = coalesce.(reciprocals, 0.0) # missing を zero で埋める | |
M = fit(PCA, top5; maxoutdim=2) | |
components = MultivariateStats.transform(M, top5) # 説明変数情報 | |
projections = projection(M) # 主成分にProjection | |
# plotly 用にデータを入力 | |
data_2d = scatter(x=projections[:,1], y=projections[:,2], | |
mode="markers+text", name="名前", | |
textposition="top center", | |
text=df[:,1], | |
marker_size=12, textfont_family="Raleway") | |
graph_data = [data_2d] | |
# 説明変数のベクトル表記をLineで表現する | |
for index in 1:size(components)[2] | |
push!(graph_data, scatter(;x=[0, components[1,index]], y=[0, components[2,index]], text=["",names(df)[index+1]], name=names(df)[index+1],textposition="top center", marker_size=1, textfont_family="Raleway, sans-serif", mode="lines+markers+text")) | |
end | |
plot(graph_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment