<jupyter_start><jupyter_text>作業Q1. 試著調整 RandomForestClassifier(...) 中的參數，並觀察是否會改變結果？<jupyter_code>from sklearn import datasets, metrics
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
# 讀取鳶尾花資料集
iris = datasets.load_iris()

# 切分訓練集/測試集
x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.25, random_state=4)

# 建立模型
for x in range(1,100,10):
    clf = RandomForestClassifier(n_estimators=x)
    clf.fit(x_train, y_train)
    y_pred = clf.predict(x_test)
    acc = metrics.accuracy_score(y_test, y_pred)
    print('n_estimator = %d' % x)
    print("Acuuracy: ", acc)
    print('-'*30)<jupyter_output>n_estimator = 1
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 11
Acuuracy:  0.9473684210526315
------------------------------
n_estimator = 21
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 31
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 41
Acuuracy:  0.9473684210526315
------------------------------
n_estimator = 51
Acuuracy:  0.9473684210526315
------------------------------
n_estimator = 61
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 71
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 81
Acuuracy:  0.9736842105263158
------------------------------
n_estimator = 91
Acuuracy:  0.9736842105263158
------------------------------<jupyter_text>Q2. 改用其他資料集 (boston, wine)，並與回歸模型與決策樹的結果進行比較<jupyter_code># 讀取波士頓資料集
boston = datasets.load_boston()

# 切分訓練集/測試集
x_train, x_test, y_train, y_test = train_test_split(boston.data, boston.target, test_size=0.1, random_state=4)

# 建立模型
for x in range(1,100,10):
    clf = RandomForestRegressor(n_estimators=x)
    clf.fit(x_train, y_train)
    y_pred = clf.predict(x_test)
    print('n_estimator = %d' % x)
    print("Mean squared error: %.2f" % mean_squared_error(y_test, y_pred))
    print('-'*30)<jupyter_output>n_estimator = 1
Mean squared error: 28.68
------------------------------
n_estimator = 11
Mean squared error: 11.48
------------------------------
n_estimator = 21
Mean squared error: 10.40
------------------------------
n_estimator = 31
Mean squared error: 9.74
------------------------------
n_estimator = 41
Mean squared error: 9.58
------------------------------
n_estimator = 51
Mean squared error: 11.15
------------------------------
n_estimator = 61
Mean squared error: 10.07
------------------------------
n_estimator = 71
Mean squared error: 9.65
------------------------------
n_estimator = 81
Mean squared error: 10.06
------------------------------
n_estimator = 91
Mean squared error: 10.20
------------------------------
{'fraction_non_alphanumeric': 0.2920385576579793, 'fraction_numerical': 0.09675116029989289, 'mean_word_length': 1.921793534932221, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '250168', 'license': 'MIT', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1051, 'n_words': 188, 'path': 'Day_044_HW.ipynb', 'repo_name': 'Olivia-CJNi/ML100-Days', 'size': '2801'}