randomForest :: importance():type = 2正在工作,但type = 1不起作用

时间:2020-02-18 13:31:33

标签: r random-forest

我正在使用randomForest软件包。为了获得可变的重要性,我使用了意义()函数。 我想更改重要性度量的类型。它由“ type”参数确定,该参数有2个可能的值:type = 1或type = 2。这是一个示例:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Buttons -->
<a href="#pricing" class="plan-select" data-plan="35000">Option1</a>
<a href="#pricing" class="plan-select" data-plan="45000">Option2</a>
<a href="#pricing" class="plan-select" data-plan="65000">Option3</a>



<!-- Form -->
<div id="pricing">
  <form id="calc">
    <select name="itemtype5" class="planlist" id="l">
      <option class="no-display" value="0">Сайт-визитка</option>
      <option value="35000">Option1</option>
      <option value="45000">Option2</option>
      <option value="65000">Option3</option>
    </select>

    <input type="checkbox" class="checkbox_check" name="itemtype1" id="d" data-genrename="Genre1" value="3000" data-time="10" />
    <label>Genre1</label>

    <input type="checkbox" class="checkbox_check" name="itemtype2" id="e" data-genrename="Genre2" value="4000" data-time="15" />
    <label>Genre</label>

    <input type="checkbox" class="checkbox_check" name="itemtype3" id="f" data-genrename="Genre3" value="10000" data-time="24" />
    <label>Genre3</label>

    <input type="checkbox" class="checkbox_check" name="itemtype4" id="g" data-genrename="Genre4" value="3000" data-time="10" />
    <label>Genre4</label>


    <label>Total:</label>
    <output name="o" class="total" for="a b c d e f g h l">35000</output>

  </form>
</div>

imp2输出:

library(randomForest)

Y = runif(100, 0.0, 1.0)
X1 = runif(100, 0.0, 1.0)
X2 = runif(100, 0.0, 1.0)

rf.model = randomForest::randomForest(Y~X1+X2)

# type 2 : mean decrease in node impurity
imp2 = randomForest::importance(x=rf.model,type=2)

# type 1 : mean decrease in accuracy
imp1 = randomForest::importance(x=rf.model,type=1)

imp1输出:

      IncNodePurity
X1      3.130248
X2      3.023091

如您所见,type = 2(节点杂质的平均减少)正在工作,但type = 1(准确性的平均减少)却没有。你知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您必须先在模型中启用它

rf.model = randomForest::randomForest(Y~X1+X2,importance=T)

然后它将起作用。

相关问题