'What is predict value of GBM model in R? and why NaN residual?
Well, I have a GBM model for nematode density with some predictor variables (SI = Spectral Index).
However, my model showed "NaN" residual with poisson distribution, and when I used predicted(gbm.fit) or gbm.fit$fit showed continuous values, but I have discrete values.
What should I use, predicted(gbm.fit) or gbm.fit$fit? What does gbm.fit$fit give me?
Can anyone help me with a problem?
This is the gbm algorithm used:
measure = read_xlsx("quantification.xlsx")
Treatament CRI GLI WI CI ACI ARI NDVI NDRE PRI NRI SIPI BI RSVI
1 10A40VIP 0.0008665688 0.5885329 0.9626913 9.346006 0.0008169200 -1.793181e-04 0.9988850 0.4022810 0.011351909 0.1395076 0.7646682 423.2938 -145.0
2 10A40VIP 0.0007029366 0.5794669 0.9604054 8.869564 0.0009034779 -1.182299e-04 0.9987221 0.3627649 0.013723696 0.1234568 0.7338175 483.2860 -167.0
3 10A40VIP 0.0008236404 0.5798046 0.9669582 9.444607 0.0008467817 -2.053200e-04 0.9988112 0.4129747 0.000000000 0.1329609 0.7549775 438.9301 -118.5
4 10A40VIP 0.0008629715 0.5902703 0.9632063 9.104881 0.0008753425 -2.055404e-04 0.9988180 0.3812155 0.009881423 0.1506229 0.7555044 439.7586 -156.0
5 10A40VIP 0.0009591620 0.6041885 0.9589175 8.593397 0.0009168128 -1.351530e-04 0.9988319 0.3340107 0.014137606 0.1730981 0.7551758 452.4927 -195.0
6 10A40VIP 0.0008564869 0.5828151 0.9555484 9.290690 0.0008184895 -1.369628e-04 0.9988631 0.3893410 0.013555787 0.1320755 0.7621073 421.2545 -155.5
7 20A12VIP 0.0008006374 0.5990220 0.9674907 8.552684 0.0009885402 -2.043577e-04 0.9987059 0.3412801 0.011535049 0.1742739 0.7378190 485.3401 -177.5
8 20A12VIP 0.0008270989 0.6006098 0.9706458 8.667173 0.0009149242 -1.383875e-04 0.9988022 0.3616162 0.016697588 0.1471215 0.7416904 467.2879 -174.0
9 20A12VIP 0.0007857894 0.5895561 0.9661485 8.777663 0.0009341785 -1.936800e-04 0.9987283 0.3653535 0.016267943 0.1409836 0.7355316 455.6322 -158.0
10 20A12VIP 0.0009601820 0.6147279 0.9578353 8.390781 0.0009219417 -7.287479e-05 0.9988647 0.3215203 0.026768642 0.1723356 0.7516689 443.4704 -205.5
PSRI VDVI INT TGI HI SI VARI BGI GRAY Hybrid rep n ovos juv all
1 0.015507125 0.2051714 414.3333 367.03 -0.1983584 0.03536068 0.3030303 0.6361940 434.026 10A40 1 2 1662.5 312 1975.0
2 0.014981273 0.1885489 474.6667 419.22 -0.1806931 0.03649635 0.2784810 0.6578073 492.238 10A40 2 2 3637.5 350 3987.5
3 0.017887564 0.1965255 430.3333 386.56 -0.1735648 0.04594595 0.2803419 0.6406534 448.819 10A40 3 2 950.0 87 1037.5
4 0.013316151 0.2129730 429.6667 384.90 -0.1966365 0.04120879 0.3079526 0.6221034 452.473 10A40 4 2 5912.5 400 6312.5
5 0.015221987 0.2418848 439.0000 398.21 -0.2178571 0.04419890 0.3440000 0.5834739 470.695 10A40 5 2 600.0 50 650.0
6 0.014995716 0.2006783 412.6667 369.91 -0.1809392 0.04384724 0.2882562 0.6365348 431.409 10A40 6 2 1412.5 250 1662.5
7 0.004729149 0.2244499 473.0000 420.51 -0.2174914 0.03404792 0.3307810 0.6118211 501.324 20A12 1 2 1200.0 162 1362.5
8 0.019317715 0.2195122 456.0000 398.25 -0.2290909 0.02343750 0.3349515 0.6250000 481.410 20A12 2 2 1812.5 262 2075.0
9 0.014128035 0.2052219 446.0000 393.55 -0.2022901 0.03285151 0.3056478 0.6377816 467.111 20A12 3 2 162.5 150 312.5
10 0.018329071 0.2508004 429.3333 381.53 -0.2466907 0.02849003 0.3712871 0.5819113 462.276 20A12 4 2 1950.0 462 2412.5
data_base$juv = as.integer(data_base$juv)
[1] 312 350 87 400 50 250 162 262 150 462 112 525 175 112 75 137 12 37 37 237 37 12 0 150 25 25 50 62 100 25 87 187 112 300 150 475 25 187 287 212 62 362 262 62
[45] 887 250 62 125 137 225 137 25 0 12 87 75 175 75 50 300 125 162 13
gbm.fit <- gbm(
formula = juv ~ NDRE + WI + GRAY + RSVI + VDVI,
distribution = "poisson",
data = data_base,
n.trees = 5000,
interaction.depth = 15,
bag.fraction = 3,
shrinkage = 0.01,
cv.folds = 5,
n.cores = NULL, # will use all cores by default
verbose = FALSE
)
Then I do:
sqrt(min(gbm.fit$fit))
Which produces this error:
Warning in sqrt(min(gbm.fit$cv.error)) : NaNs produced
[1] NaN
And these values with "gbm$fit":
[1] 5.343713 5.343713 5.306180 5.343713 5.302584 5.323861 4.727604 5.326180 5.306180 5.337155 4.831587 5.364401 5.278518 4.589127 4.597222 4.589127
[17] 4.589127 4.590736 4.594000 4.613099 4.603262 4.591220 4.578044 4.591220 4.588643 4.597541 4.635105 4.495786 4.668155 4.589127 5.306180 5.294698
[33] 4.658997 5.314817 5.082870 5.326683 4.556606 5.210249 5.875102 4.913479 5.074356 4.972662 5.127610 4.952755 5.875102 5.127610 5.306180 5.225729
[49] 4.644862 5.304346 5.343713 4.585413 4.913479 4.913087 4.917535 5.255368 5.047442 4.940355 4.913087 5.241524 5.057900 4.928785 4.928785
gbm.perf(gbm.fit, method = "cv")
[1] 844
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
