-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
no method match fit while running PCA #71
Comments
it turns out that the transposed array is not an array any more! I have to convert it to Array again! julia> a = rand(5,3)'
3×5 LinearAlgebra.Adjoint{Float64,Array{Float64,2}}:
0.165982 0.118656 0.541775 0.515358 0.737706
0.20481 0.443253 0.199402 0.507814 0.694907
0.427047 0.831928 0.75973 0.0487185 0.595516 using MultivariateStats, RDatasets, Plots
plotly() # using plotly for 3D-interacive graphing
# load iris dataset
iris = dataset("datasets", "iris")
# split half to training set
@show iris[1:2:end,1:4]
Xtr = convert(Array, iris[1:2:end,1:4])' |> Array
@show Xtr
@show typeof(Xtr)
@show size(Xtr)
Xtr_labels = convert(Array, iris[1:2:end,5])
# split other half to testing set
Xte = convert(Array,iris[2:2:end,1:4])' |> Array
Xte_labels = convert(Array,iris[2:2:end,5])
# suppose Xtr and Xte are training and testing data matrix,
# with each observation in a column
# train a PCA model, allowing up to 3 dimensions
M = fit(PCA, Xtr; maxoutdim=3)
# apply PCA model to testing set
Yte = transform(M, Xte)
# reconstruct testing observations (approximately)
Xr = reconstruct(M, Yte)
# group results by testing set labels for color coding
setosa = Yte[:,Xte_labels.=="setosa"]
versicolor = Yte[:,Xte_labels.=="versicolor"]
virginica = Yte[:,Xte_labels.=="virginica"]
# visualize first 3 principal components in 3D interacive plot
p = scatter(setosa[1,:],setosa[2,:],setosa[3,:],marker=:circle,linewidth=0)
scatter!(versicolor[1,:],versicolor[2,:],versicolor[3,:],marker=:circle,linewidth=0)
scatter!(virginica[1,:],virginica[2,:],virginica[3,:],marker=:circle,linewidth=0)
plot!(p,xlabel="PC1",ylabel="PC2",zlabel="PC3") I still got some other error though:
|
checked the code, not sure why there is such an error. I switched to svd method, it works for me now. |
Switch to |
New version released, JuliaLang/METADATA.jl#17965 |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
I am running the example code from documentation, but get some error.
I removed the DataArray to since it was not defined in Julia 0.7 packages.
I am getting the following errors:
The text was updated successfully, but these errors were encountered: