jasp-stats / jasp-issues

This repository is solely meant for reporting of bugs, feature requests and other issues in JASP.
58 stars 29 forks source link

[Bug]: explain predictions not working for random forest regression #2731

Closed TarandeepKang closed 4 months ago

TarandeepKang commented 4 months ago

JASP Version

0.18.3

Commit ID

No response

JASP Module

Machine Learning

What analysis are you seeing the problem on?

random forest regression

What OS are you seeing the problem on?

Windows 11

Bug Description

Explain predictions causes an error message for a random forest regression

Expected Behaviour

Someone on the forum has been discussing shapely values, so this new explain predictions feature was mentioned. Before I start using it for a paper I'm writing, I want to get a feel of how it works. I therefore tried to use it with the album sales dataset from the data library.

Steps to Reproduce

I therefore tried to use it with the album sales dataset from the data library. And then click on predictions but I get this message:

Album Sales: Linear Regression

Description:

This fictional data set, "Album Sales", provides factors that may influence album sales.

Variables:

  • adverts - Amount (in thousands of pounds) spent promoting the album before release.
  • sales - Sales (in thousands of copies) of each album in the week after release.
  • airplay - How many times songs from the album were played on a prominent national radio station in the week before release.
  • attract - How attractive people found the band's image (1 to 10).

This example JASP file demonstrates the use of linear regression. First, we will fit a simple model to see whether the adverts predict album sales. Then, we will test whether adding airplay and attractiveness improves the predictions of the model.

Reference:

Field, A. P. (2017). Discovering Statistics Using IBM SPSS Statistics (5th ed.). London: Sage. [Fictional data set]

The data set was constructed by Andy Field who therefore owns the copyright. Andy Field generously agreed that we can include the data set in the JASP data library. This data set is also publicly available on the website that accompanies Andy Field`s book, https://edge.sagepub.com/field5e. Without Andy Field`s explicit consent, this data set may not be distributed for commercial purposes, this data set may not be edited, and this data set may not be presented without acknowledging its source (i.e., the terms of a CC BY-NC-ND license).

Descriptive Statistics

Before conducting the analysis, it is good to produce some descriptive statistics.

First we will consider only two variables - sales predicted by adverts. 

The descriptive statistics show us that we have 200 cases.

Descriptive Statistics -- Valid |   | 200 |   | 200 |   |   Missing |   | 0 |   | 0 |   Mean |   | 193.200 |   | 614.412 |   Std. Deviation |   | 80.699 |   | 485.655 |   Minimum |   | 10.000 |   | 9.104 |   Maximum |   | 360.000 |   | 2271.860 |    
This analysis terminated unexpectedly.

Error in UseMethod('predict'): no applicable method for 'predict' applied to an object of class 'randomForest'

Stack trace
feature_importance.default(model, data, y, predict_function = predict_function, loss_function = loss_function, label = label, type = type, N = N, n_sample = n_sample, B = B, variables = variables, variable_groups = variable_groups, ...)

replicate(B, loss_after_permutation())

sapply(integer(n), eval.parent(substitute(function(...) expr)), simplify = simplify)

lapply(X = X, FUN = FUN, ...)

FUN(X[[i]], ...)

loss_after_permutation()

loss_function(observed, predict_function(x, sampled_data))

mean((observed - predicted)^2, na.rm = na.rm)

predict_function(x, sampled_data)

predict(model, newdata = data, type = 'response')

To receive assistance with this problem, please report the message above at: https://jasp-stats.org/bug-reports

Log (if any)

No response

Final Checklist

github-actions[bot] commented 4 months ago

@TarandeepKang, thanks for taking the time to create this issue. If possible (and applicable), please upload to the issue website (https://github.com/jasp-stats/jasp-issues/issues/2731) a screenshot showcasing the problem, and/or a compressed (zipped) .jasp file or the data file that causes the issue. If you would prefer not to make your data publicly available, you can send your file(s) directly to us, issues@jasp-stats.org

koenderks commented 4 months ago

I cannot replicate this problem, it works on my JASP 0.18.3 release:

image

Can you replicate the issue and then save the file as a .jasp file, then zip this file and upload it here?

TarandeepKang commented 4 months ago

I tried again this morning and for some reason it looks like it's working now, so I guess we can close this?