Skip to content

Provide a way to get test set predictions from evaluate #837

Open
@ericphanson

Description

@ericphanson

Like https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_predict.html (pointed out by @josephsdavid!)

Currently, I am doing it manually, which works fine:

X = DataFrame(df.features)
y = df.label

stratified_cv = StratifiedCV(; nfolds=6,
                                 shuffle=true,
                                 rng=StableRNG(123))

tt_pairs = MLJBase.train_test_pairs(stratified_cv, 1:nrow(X), y)

cv = []
predictions = DataFrame()
for (train_indices, test_indices) in tt_pairs
        model = ...
        mach = machine(model, X[train_indices, :], y[train_indices])
        MLJ.fit!(mach)

        push!(cv, (; machine=mach, train_indices, test_indices))

        ŷ = MLJ.predict(mach, X[test_indices, :])

        append!(predictions, hcat(df[test_indices, :], DataFrame(:prediction => ŷ)))

end

It would be nice if evaluate could give the predictions as well, since it needs to generate them anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions