Unsupervised models
Unsupervised models implement the MLJ model interface in a very similar fashion. The main differences are:
The
fit
method, which still returns(fitresult, cache, report)
will typically have only one training argumentX
, as inMLJModelInterface.fit(model, verbosity, X)
, although this is not a hard requirement. For example, a feature selection tool (wrapping some supervised model) might also include a targety
as input. Furthermore, in the case of models that subtypeStatic <: Unsupervised
(see Static models)fit
has no training arguments at all, but does not need to be implemented as a fallback returns(nothing, nothing, nothing)
.A
transform
and/orpredict
method is implemented, and has the same signature aspredict
does in the supervised case, as inMLJModelInterface.transform(model, fitresult, Xnew)
. However, it may only have one data argumentXnew
, unlessmodel <: Static
, in which case there is no restriction. A use-case forpredict
is K-means clustering thatpredict
s labels andtransform
s input features into a space of lower dimension. See the Transformers that also predict section of the MLJ manual for an example.The
target_scitype
refers to the output ofpredict
, if implemented. A new trait,output_scitype
, is for the output oftransform
. Unless the model isStatic
(see Static models) the traitinput_scitype
is for the single data argument oftransform
(andpredict
, if implemented). Iffit
has more than one data argument, you must overload the traitfit_data_scitype
, which bounds the alloweddata
passed tofit(model, verbosity, data...)
and will always be aTuple
type.An
inverse_transform
can be optionally implemented. The signature is the same astransform
, as inMLJModelInterface.inverse_transform(model, fitresult, Xout)
, which:- must make sense for any
Xout
for whichscitype(Xout) <: output_scitype(SomeSupervisedModel)
(see below); and - must return an object
Xin
satisfyingscitype(Xin) <: input_scitype(SomeSupervisedModel)
.
- must make sense for any
For sample implementatations, see MLJ's built-in transformers and the clustering models at MLJClusteringInterface.jl.