1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】scikit-learnのランダムフォレストに関して

Posted at

決定木の集合であり、ランダムフォレストのように複数の学習器を用いた学習方法をアンサンブル学習と呼ぶ。

複数の決定木を利用して多数決で予測するため、モデルの内容を可視化するのは難しい。

単独の決定木は訓練データに対して過剰適合する傾向があるが、ランダムフォレストは過剰適合の度合いを減らすことができる。

n_estimatorsは決定木の数を指定する引数です。

次のコードはランダムフォレストの例です。

from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimator=100)

model.fit(X_train, y_train)
model.predict(X_test)

2行目でRandomForestClassifierクラスをインスタンス化する際に、「n_estimator=100」と指定しています。これは決定木の深さではなく、決定木の数を指定しています。

ランダムフォレストも単独の決定木と同様に、引数「max_depth」でツリーの深さを指定することができますが、決定木の数を十分大きくできる場合は、深さを指定する必要はありません。

ランダムフォレストは複数の決定木を利用して多数決で予測するため、単独の決定木より過剰適合の度合いを減らすことができます。ただし、複数の決定木を使うため、単独の決定木のようにモデルの内容をツリーで可視化するのは難しいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?