ランダムフォレストの実装

下記の設問に対する答えとして相応しものを選択肢から選び、次のコードの空欄(##########)を埋めてください.

from sklearn.model_selection import train_test_split
from sklearn.datasets import make_moons

X, y = make_moons(n_samples=500, noise=0.30, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

import numpy as np
# Q1:ランダムフォレスト用のクラスをインポートしてください.
from sklearn.ensemble import ##########

[Q1 選択肢]
1. DecisionTreeClassifaier
2. BaggingClassifier
3. EnsembleClassifier
4. RandomForestClassifier

# Q1:RndomForestClassifier() クラスを用いて訓練セットをアンサンブル学習してください.
rnd_c = ##########

rnd_c.fit(X_train, y_train)

y_pred_rf = rnd_c.predict(X_test)
print(np.sum(y_pred == y_pred_rf) / len(y_pred)

[Q1の選択肢]
1. RandomForestClassifier(n_estimators=500, max_nodes=16,
                   n_jobs=-1, random_state=0)
2. RandomForestClassifier(n_estimators=500, max_leaf_nodes=16,
                   n_jobs=-1, random_state=0)
3. RandomForestClassifier(n_estimators=500, leaf=16,
                   n_jobs=-1, random_state=0)

Leave a comment

Your email address will not be published. Required fields are marked *