Skip to content

Instantly share code, notes, and snippets.

@pazzo83
Created July 6, 2021 00:22
Show Gist options
  • Save pazzo83/61b09a3821145baf889896c6f4160d6e to your computer and use it in GitHub Desktop.
Save pazzo83/61b09a3821145baf889896c6f4160d6e to your computer and use it in GitHub Desktop.
using MLJModelInterface, MLJBase, TSVD
MLJModelInterface.@mlj_model mutable struct TSVDTransformer <: MLJModelInterface.Unsupervised
nvals::Int = 2
maxiter::Int = 1000
end
struct TSVDTransformerResult
singular_values::Vector{Float64}
components::Matrix{Float64}
end
function MLJBase.fit(transformer::TSVDTransformer, verbosity::Int, X)
U, s, V = tsvd(X, transformer.nvals; maxiter=transformer.maxiter)
res = TSVDTransformerResult(s, V)
return res, nothing, NamedTuple()
end
function MLJBase.transform(::TSVDTransformer, result, X)
X_transformed = X * result.components
return X_transformed
end
@pazzo83
Copy link
Author

pazzo83 commented Jul 20, 2021

I wasn't sure about the workflow and I think I might have corrupted the repository you created. Would you mind recreating it?

@ablaom
Copy link

ablaom commented Jul 20, 2021

No worries. I'll also set up a bit more of a proper skeleton to make it easier.

@pazzo83
Copy link
Author

pazzo83 commented Jul 21, 2021

Great, thank you!

@ablaom
Copy link

ablaom commented Jul 21, 2021

Done: https://github.com/JuliaAI/MLJTSVDInterface.jl .

It's still private for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment