Comments (3)
@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.
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.
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)
- Duplicate row.names are not allowed. HOT 4
- Allow fitting models on raster stacks of differing extents HOT 3
- Training data error superClass HOT 1
- MTL file error HOT 2
- Please attend to retirement of rgdal, rgeos and maptools HOT 1
- No plot with ggRGB(rlogo, ggLayer = TRUE)
- Problems with readMeta
- Stale CRS in stored objects
- Please remove dependencies on **rgdal**, **rgeos**, and/or **maptools** HOT 3
- topCor
- Error: rasterCVA
- ggR with classified raster HOT 1
- CRAN Archival 2023-02-12 HOT 8
- error in evaluating the argument 'y' in selecting a method for function 'intersect': non-character object(s)
- R fatal error when using unsuperClass from RStoolbox HOT 4
- `superClass` unable to predict when there is NA in raster data HOT 3
- Fails to run superClass when providing the `model` parameter
- Fails to run ggRGB with stacked rasters HOT 4
- Implementation of Sentenel-2 Tasseled Cap
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rstoolbox.