JuliaTrustworthyAI / CounterfactualExplanations.jl

A package for Counterfactual Explanations and Algorithmic Recourse in Julia.
https://juliatrustworthyai.github.io/CounterfactualExplanations.jl/
MIT License
117 stars 7 forks source link

ERROR: LoadError: Cannot convert CounterfactualData to series data for plotting #462

Open feldob opened 1 month ago

feldob commented 1 month ago

I am trying to follow the tutorial and run into problems. This is the error I get for the first code snippet on the page:

ERROR: LoadError: Cannot convert CounterfactualData to series data for plotting
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] _prepare_series_data(x::CounterfactualData)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:8
  [3] _series_data_vector(x::CounterfactualData, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:36
  [4] macro expansion
    @ ~/.julia/packages/RecipesPipeline/BGM3l/src/series.jl:129 [inlined]
  [5] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, ::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:300
  [6] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/user_recipe.jl:38
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/BGM3l/src/RecipesPipeline.jl:72
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/du2dt/src/plot.jl:223
  [9] plot!(plt::Plots.Plot, args::Any; kw...)
    @ Plots ~/.julia/packages/Plots/du2dt/src/plot.jl:213
 [10] plot!(args::Any; kw...)
    @ Plots ~/.julia/packages/Plots/du2dt/src/plot.jl:202
 [11] scatter!(args::Any; kw...)
    @ Plots ~/.julia/packages/RecipesBase/BRe07/src/RecipesBase.jl:429
 [12] top-level scope
    @ /usr/src/app/script.jl:9
in expression starting at /usr/src/app/script.jl:9

Seems like some sort of binding is missing to the plotting library to support the library specific structs. Do I need additional dependencies or loaded modules? I created a Dockerfile and a script for reproducibility:

FROM julia:rc-bookworm

# Set the working directory
WORKDIR /usr/src/app

# Install required Julia packages
RUN julia -e 'using Pkg; Pkg.add(url="https://github.com/JuliaTrustworthyAI/TaijaData.jl")'
RUN julia -e 'using Pkg; Pkg.add(url="https://github.com/JuliaTrustworthyAI/CounterfactualExplanations.jl")'
RUN julia -e 'using Pkg; Pkg.add("Plots")'

# Copy the Julia script into the container
COPY script.jl .

# Command to run the script
CMD ["julia", "script.jl"]

For completeness, here is the code from script.jl:

using CounterfactualExplanations, TaijaData, Plots

n = 500
data = TaijaData.load_moons(n)
counterfactual_data = CounterfactualExplanations.DataPreprocessing.CounterfactualData(data...)
X = counterfactual_data.X
y = counterfactual_data.y
plt = plot()
scatter!(counterfactual_data)

Best Regards Felix

pat-alt commented 1 month ago

Hi Felix, the piece that's missing here is using TaijaPlotting. That part of the code is omitted in the tutorial although it probably shouldn't be. Sorry about this and thanks for flagging. I'll keep this issue open as a reminder to update the docs.