Skip to content

Conversation

@ablaom
Copy link
Member

@ablaom ablaom commented Oct 20, 2025

Merge conflicts will be best managed if this PR is merged after:

  • Forthcoming update to bump the compat for CategoricalArrays to 1.0 (WIP of @ablaom)

Density estimators

This PR adds evaluate support for density estimators. According to the API docs such a
model is viewed as Probabilistic <: Supervised but provided X = nothing as
features. The target y are the samples to be fitted, and yhat = predict(model, nothing)
outputs a single pdf, the density being sought. A typical workflow using such a model might look like this:

y = <samples>
mach = machine(model, nothing, y) # `nothing` instead of features
fit!(mach)
yhat = predict(mach, nothing) # single pdf
log_loss(fill(yhat, length(y)), y)  # get an aggregate of the loss based on multiple samples, so need `fill` here

At present evaluate is unsupported because it tries to pair the single yhat with
multiple ground truth values y. The mitigation provided in this PR is to replace yhat with
FillArrays.Fill(yhat, nrows(y)) (a lazy version of fill(yhat, nrows(y))) in the case
that X == nothing. So then the following works:

evaluate(model, nothing, y, measure=log_loss)

After this PR is merged:

  • Update [this link] so that it points to the example at the end of test/resampling.jl
    instead (some testing has been moved over in this PR). [tracked here]

cc @LucasMatSP

@ablaom ablaom marked this pull request as draft October 20, 2025 23:53
ytest = y[test]
yhat = predict(mach, nothing) # single UnivariateFinite distribution

# Estmiate out-of-sample loss. Notice we have to make duplicate versions `yhat`, to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo Estmiate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (5d6034e) to head (3590364).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1026      +/-   ##
==========================================
+ Coverage   88.95%   90.28%   +1.33%     
==========================================
  Files          28       28              
  Lines        2526     2574      +48     
==========================================
+ Hits         2247     2324      +77     
+ Misses        279      250      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants