バギングによるアンサンブル学習の実装

次のコードで空欄になっている行に入る適切な選択肢を選び、バギングによるアンサンブル学習モデルを訓練してください.

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)

# Q1:BaggingClassifier をインポートしてください.
from ########## import BaggingClassifier

[Q1 選択肢]
1. sklearn.ensemble
2. sklearn.model_selection
3. sklearn.decomopsition
4. sklearn.tree

from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

# Q2:BaggingClassifier() クラスを用いてバギングありで決定木をアンサンブル学習させてください.( 1 行 )
# † :学習器の数は 500、random_state = 0、 CPU コアは全て使用してください.

bag_c = ##########
bag_c.fit(X_train, y_train)
y_pred = bag_c.predict(X_test)

print(accuracy_score(y_test, y_pred))

[Q2の選択肢]
1.
BaggingClassifier(
DecisionTreeClassifier(random_state=0), n_estimators=500,
max_samples=100, bootstrap=True, n_jobs=-1, random_state=0)

2.
BaggingClassifier(
DecisionTreeClassifier(random_state=0, max_iter=100), estimators=500,
bootstrap=False, n_jobs=1, random_state=0)

3.
BaggingClassifier(
 n_estimators=500, max_samples=100,
 bootstrap=True, n_jobs=1, random_state=0)

Leave a comment

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