MultivariateStats.transform ,MethodError:

How to overcome that Method error ?

Data

7043×2 Matrix{Float64}:
 -1.27735    -1.16024
  0.0663227  -0.259611
 -1.23664    -0.362635
  0.514215   -0.746482
 -1.23664     0.197351
 -0.992332    1.15946
 -0.422287    0.808849
  ⋮          
  1.61359    -1.44937
 -0.340852    0.665945
  1.61359     1.27744
 -0.870179   -1.16855
 -1.1552      0.320315
  1.36928     1.35886
Data= (data .- mean(data,dims=1))./std(data,dims=1)
p

PCA(indim = 7043, outdim = 1, principalratio = 1.0)
p=fit(PCA,Data,maxoutdim=2)
7043×1 Matrix{Float64}:
 -0.0011379038573442269
  0.003166852111996749
 -0.00849202937785105
  0.01224926425921756
 -0.013932997653130772
 -0.020907400623596868
 -0.011962038872230636
  ⋮
  0.029760511490590863
 -0.009782299361486769
  0.003266063598205041
  0.0028990384530702905
 -0.014336507175160657
  0.00010121411503414527
projection(p)
P

7043×1 Matrix{Float64}:
 -0.0011
  0.0032
 -0.0085
  0.0122
 -0.0139
 -0.0209
 -0.012
  ⋮
  0.0298
 -0.0098
  0.0033
  0.0029
 -0.0143
  0.0001
P=round.(projection(p), digits=4)
MethodError: no method matching predict(::Matrix{Float64}, ::Matrix{Float64})

Closest candidates are:

predict(!Matched::MultivariateStats.FactorAnalysis, ::AbstractVecOrMat{T}) where T<:Real at ~/.julia/packages/MultivariateStats/zLpz8/src/fa.jl:64

predict(!Matched::MultivariateStats.ICA, ::AbstractVecOrMat{<:Real}) at ~/.julia/packages/MultivariateStats/zLpz8/src/ica.jl:38

predict(!Matched::MultivariateStats.SubspaceLDA, ::AbstractVecOrMat{T}) where T<:Real at ~/.julia/packages/MultivariateStats/zLpz8/src/lda.jl:427

...

    transform(::Matrix{Float64}, ::Matrix{Float64})@deprecated.jl:72
    top-level scope@Local: 1[inlined]
yte=MultivariateStats.transform(P,data)

AFAICT you should call transform(p, data) instead (small p).

can you explain me - why i should use small “p” instead of Capital “P” ? Actually MultivariateStats don’t have elaborate documentations.

It’s not specific to MultivariateStats, it’s just that you called p=fit(PCA,Data,maxoutdim=2) and later P=round.(projection(p), digits=4) so the PCA object is stored in p, while P holds the (rounded) projection matrix.

1 Like