0

RandomForestRegresser と GradietBoostRegressor のツリーの数と OOB エラーを視覚化したいと考えています。だから私はこの行をコーディングしましたが、何らかの理由で「numpy.ndarray」オブジェクトは呼び出し可能ではありません。これが機能しなかった理由を知っている人はいますか? 良い一日をお過ごしください。ありがとうございます。

train_results = []
test_results = []
list_nb_trees = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65,70 , 75, 80, 85, 90, 95, 100]

for nb_trees in list_nb_trees:
    rf = RandomForestRegressor(n_estimators=nb_trees,
                               max_depth= None,
                               max_features= 50,
                               min_samples_leaf= 5,
                               min_samples_split= 2,
                               random_state= 42,
                               oob_score= True, 
                               n_jobs= -1)
    rf.fit(X_train_v1, y_train_v1)

train_results.append(mean_squared_error(y_train_v1, rf.oob_prediction_(X_train_v1)))
test_results.append(mean_squared_error(y_test_v1, rf.oob_prediction_(X_test_v1)))

plt.figure(figsize=(15, 5))
line2, = plt.plot(list_nb_trees, test_results, color="g", label="Test OOB Score")
line1, = plt.plot(list_nb_trees, train_results, color="b", label="Training  OOB Score")
plt.title('Trainings- und Test Out-of-Bag Score')
plt.legend(handler_map={line1: HandlerLine2D(numpoints=2)})
plt.ylabel('MSE')
plt.xlabel('n_estimators')
plt.show()
/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/forest.py:737: UserWarning: Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.
  warn("Some inputs do not have OOB scores. "
/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/forest.py:737: UserWarning: Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.
  warn("Some inputs do not have OOB scores. "
/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/forest.py:737: UserWarning: Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.
  warn("Some inputs do not have OOB scores. "
/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/forest.py:737: UserWarning: Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.
  warn("Some inputs do not have OOB scores. "
/opt/conda/lib/python3.7/site-packages/sklearn/ensemble/forest.py:737: UserWarning: Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.
  warn("Some inputs do not have OOB scores. "
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-282-80f6bbb31b23> in <module>
     14     rf.fit(X_train_v1, y_train_v1)
     15 
---> 16 train_results.update(mean_squared_error(y_train_v1, rf.oob_prediction_(X_train_v1)))
     17 test_results.update(mean_squared_error(y_test_v1, rf.oob_prediction_(X_test_v1)))
     18 

TypeError: 'numpy.ndarray' object is not callable
4

1 に答える 1