JuliaStats / MultivariateStats.jl

A Julia package for multivariate statistics and data analysis (e.g. dimension reduction)
Other
379 stars 86 forks source link

MulticlassLDA documentation #202

Closed pnavaro closed 2 years ago

pnavaro commented 2 years ago

The documentation of fit function for MulticlassLDA wasn't displayed. I think i fixed it. There is no example for LDA so i made a simple one but I am not sure you want it. I can add it to the PR it you are interested. This is the scikit-learn example though.

using MultivariateStats, RDatasets, Plots

iris = dataset("datasets", "iris")

X = Matrix(iris[1:2:end,1:4])'
X_labels = Vector(iris[1:2:end,5])

pca = fit(PCA, X; maxoutdim=2)
Ypca = predict(pca, X)

lda = fit(MulticlassLDA, X, X_labels; outdim=2)
Ylda = predict(lda, X)

p = plot(layout=(1,2), size=(900,300))

for s in ["setosa", "versicolor", "virginica"]

    points = Ypca[:,X_labels.==s]
    scatter!(p[1], points[1,:],points[2,:],marker=:circle,linewidth=0, 
             label=s, legend=:bottomleft)
    points = Ylda[:,X_labels.==s]
    scatter!(p[2], points[1,:],points[2,:],marker=:circle,linewidth=0, 
             label=s, legend=:bottomleft)

end
display(p)
wildart commented 2 years ago

And example for LDA would be a nice addition. If you decide to submit PR, please follow the structure of PCA docs.

pnavaro commented 2 years ago

Thanks for your useful comments. I append the example to the LDA page.

wildart commented 2 years ago

You may want to move example in the beginning on the page, just under the LDA description. So it will show up in TOC in the first place.

pnavaro commented 2 years ago

You may want to move example in the beginning on the page, just under the LDA description. So it will show up in TOC in the first place.

Yes it's consistent with the page on principal component analysis.