2017-05-31 22 views
1

如何獲得用固定n.trees計算的gbm的交互評估? 我想:gbm.interactions for gbm.fixed

data(Anguilla_train) 
angaus.fixed <- gbm.fixed(data=Anguilla_train, gbm.x = 3:13, 
    gbm.y = 2,family = "bernoulli", tree.complexity = 5, learning.rate = 0.01, 
    bag.fraction = 0.5, n.trees = 5000) 
find.int <- gbm.interactions(angaus.fixed) 

但是:

1錯誤[.data.frame(pred.frame,N):未定義列 選擇

回答

1

dismo::gbm.interactions功能進行仔細檢查後,我發現dismo::gbm.fixed返回的對象與gbm.interactions不完全兼容。
這裏是你的代碼如何被修改:

library(dismo) 
data(Anguilla_train) 
angaus.fixed <- gbm.fixed(data=Anguilla_train, gbm.x = 3:13, 
    gbm.y = 2,family = "bernoulli", tree.complexity = 5, learning.rate = 0.01, 
    bag.fraction = 0.5, n.trees = 5000) 

# Change the name of angaus.fixed$gbm.call$data with angaus.fixed$gbm.call$dataframe 
names(angaus.fixed$gbm.call)[1] <- "dataframe" 

find.int <- gbm.interactions(angaus.fixed) 

###### 
gbm.interactions - version 2.9 
Cross tabulating interactions for gbm model with 11 predictors 
1 2 3 4 5 6 7 8 9 10 

現在gbm.interactions作品精美,得到以下結果:

find.int$interactions 

####### 
      SegSumT SegTSeas SegLowFlow DSDist DSMaxSlope USAvgT USRainDays USSlope USNative DSDam Method 
SegSumT   0 28.35  0.88 150.10  13.20 24.38  30.30 17.85 22.57 0.27 44.68 
SegTSeas   0  0.00  17.66 130.69  7.96 16.93  3.14 18.59 25.90 0.14 4.15 
SegLowFlow  0  0.00  0.00 5.92  3.85 6.88  4.69 10.85  5.06 0.09 6.23 
DSDist   0  0.00  0.00 0.00  2.40 10.68  47.77 41.54  6.82 0.01 11.42 
DSMaxSlope  0  0.00  0.00 0.00  0.00 3.22  2.85 3.80  2.64 0.00 1.25 
USAvgT   0  0.00  0.00 0.00  0.00 0.00  3.08 11.76 24.90 0.04 1.94 
USRainDays  0  0.00  0.00 0.00  0.00 0.00  0.00 4.69 15.26 0.09 18.16 
USSlope   0  0.00  0.00 0.00  0.00 0.00  0.00 0.00 12.08 0.03 19.44 
USNative   0  0.00  0.00 0.00  0.00 0.00  0.00 0.00  0.00 0.02 12.79 
DSDam   0  0.00  0.00 0.00  0.00 0.00  0.00 0.00  0.00 0.00 0.13 
Method   0  0.00  0.00 0.00  0.00 0.00  0.00 0.00  0.00 0.00 0.00 


find.int$rank.list 

####### 
    var1.index var1.names var2.index var2.names int.size 
1   4  DSDist   1 SegSumT 150.10 
2   4  DSDist   2 SegTSeas 130.69 
3   7 USRainDays   4  DSDist 47.77 
4   11  Method   1 SegSumT 44.68 
5   8 USSlope   4  DSDist 41.54 
6   7 USRainDays   1 SegSumT 30.30 
+0

非常感謝。代碼運行完美,非常有用。 –

+0

@ F.Johann我很高興我的答案可以幫助你!請考慮upvote我的答案並關閉問題(https://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow) –