Git Product home page Git Product logo

Comments (3)

KonstiDE avatar KonstiDE commented on August 11, 2024 1

@bappa10085 You are correct, caret converts it, however, terra does not. I am first using terra::predict before feeding anything into caret which seems to have some problems with factors. I will investigate on that, thanks for reporting. For now, just convert your SpatRaster "Class" (the values of it) to numeric before it then gets coverted by caret again to factors. As follows:

logo$Class <- as.numeric(logo$Class)
rf_mod <- superClass(logo,
                     trainData = sf::st_as_sf(v),
                     responseCol = "pb",
                     model = "rf",
                     tuneLength = 1,
                     trainPartition = 0.7,
                     predict = T,
                     predType = "prob", #for class probabilities
                     mode = "classification",
                     kfold = 3, na.rm=TRUE)

plot(rf_mod$map)

from rstoolbox.

fstrech avatar fstrech commented on August 11, 2024

Does caret know how to convert the logo$Class back into a factor variable? The training data after the model suggests it treated Class as a pure numeric variable (only 6 of the 9 levels from Class are represented in the training data):

rf_mod$model$trainingData
.outcome elevation slope Class
1 Yes 352 0.9963959 4
2 Yes 277 5.0016905 8
3 Yes 318 0.9194205 4
4 Yes 380 1.4358448 5
5 Yes 336 4.8786019 9
6 Yes 428 1.0746833 4
7 Yes 490 0.9363304 4
8 No 325 0.7089894 3
9 No 253 3.1731447 4
10 No 396 2.3262434 7
11 No 358 1.2676616 4
12 No 354 1.1709739 4
13 No 424 2.2205044 3
14 No 463 1.1765749 9

from rstoolbox.

KonstiDE avatar KonstiDE commented on August 11, 2024

If I understand u right its just a matter of training data, not about conversion.

Executing

rf_mod <- RStoolbox::superClass(logo, trainData = sf::st_as_sf(v),
                     responseCol = "pb",
                     model = "rf", tuneLength = 1, trainPartition = 0.7,
                     predict = T,
                     predType = "prob", #for class probabilities
                     mode = "classification",
                     kfold = 3, na.rm=TRUE)
length(unique(rf_mod$model$trainingData$Class))

gives back sometimes 6, 7, or 8 for me and maybe 10 test runs. It can be, that just the training split was randomly selected that some classes either are exclusively within the validation or training set or are just not really represented enough anymore to be predicted...

from rstoolbox.

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.