Git Product home page Git Product logo

Comments (5)

valeman avatar valeman commented on September 22, 2024 2

Here is more relevant paper that deals with any underlying regressor https://proceedings.mlr.press/v91/vovk18a.html
And toy Python package that implements it https://pypi.org/project/pysloth/

from conformalprediction.jl.

azev77 avatar azev77 commented on September 22, 2024 1

I had a look at the slides:

using MLJ, EvoTrees, ConformalPrediction, Plots, Random, MLJLinearModels, Tables;
########################################
n= 100_000; p=70; σ=100.10;
X = [ones(n) randn(MersenneTwister(49), n, p-1)]
θ = randn(MersenneTwister(49), p)
CEF   = X*θ 
Noise = σ*randn(MersenneTwister(49), n)
y = CEF + Noise
train, calibration, test = partition(eachindex(y), 0.4, 0.4)
########################################
LinearRegressor = @load LinearRegressor pkg=MLJLinearModels
model = LinearRegressor(fit_intercept = false) 
mach = machine(model, Tables.table(X), y)
fit!(mach, rows=train)
pr_y = predict(mach, rows=test)
########################################
conf_mach = conformal_machine(mach)
calibrate!(conf_mach, selectrows(X, calibration), y[calibration])
pr = predict(conf_mach, X[test,:]; coverage=0.95)
pr_lower = [pr[j][1][2][] for j in 1:length(test)]
pr_upper = [pr[j][2][2][] for j in 1:length(test)]
mean(pr_lower .<= y[test] .<= pr_upper)   # 0.94975
###########################################
# recover the predicted distribution
xt = [X[test[1],:] ;;]'
c_grid = .01:.001:0.99 
LB = []; UB = [];
for j in eachindex(c_grid)
    pr = predict(conf_mach, xt; coverage=c_grid[j] )
    push!(LB, pr[1][1][2][])
    push!(UB, pr[1][2][2][])
end
plot(legend=:topleft)
plot!(LB, (1.0 .- c_grid)/2.0, lab="LB, quantile")
plot!(UB, (c_grid[end]/2.0) .+ (c_grid)/2.0, lab="UB, quantile")
plot!([pr_y[1]], seriestype = :vline, lab="y prediction, median", color="red") 

Gives the ECDF (centered at the median)
image

Shouldn't the "density" be the derivative of the ECDF?

from conformalprediction.jl.

azev77 avatar azev77 commented on September 22, 2024

Question: how do I plot the predicted distribution of y at a given x?

#AZ: recover the predicted distribution? 
xt = [X[test[1],:] ;;]'
c_grid = .01:.01:0.99 
LB = []; UB = [];
for j in eachindex(c_grid)
    pr = predict(conf_mach, xt; coverage=c_grid[j] )
    push!(LB, pr[1][1][2][])
    push!(UB, pr[1][2][2][])
end
plot(legend=:topleft)
plot!(LB, 1.0 .- c_grid, lab="LB at %-ile")
plot!(UB, 1.0 .- c_grid, lab="UB at %-ile")
plot!([pr_y[1]], seriestype = :vline, lab="y prediction point estimate", color="red") 

image
To be clear, I'm fairly confident that what I plotted above is not the predicted density of y given x.
My question is how to recover it...

from conformalprediction.jl.

pat-alt avatar pat-alt commented on September 22, 2024

Hi @azev77! Great to see you've already played around with the package. I understand what you have in mind and that would certainly be nice feature to add. It can apparently be done as demonstrated in this paper by @valeman and co-authors, but the package does not support this yet. For now all you can really produce is prediction intervals. Adding support for this in the future would be nice, but it looks too involved for me to do that any time soon. Here's a corresponding tutorial if you want to have a go at it yourself. Or perhaps I'm overthinking this and others know of a straight-forward way to do what you have in mind.

What you have plotted is the user-chosen error rate $\alpha$ as a function of $\hat{y}$ as far as I can tell. I'm not quite sure what to make of this right now, but it is definitely not the predictive posterior $\hat{f}(y|x)$.

from conformalprediction.jl.

pat-alt avatar pat-alt commented on September 22, 2024

Thanks @azev77 - just linking the related thread on discourse here for info.

from conformalprediction.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.