Я хочу визуализировать количество деревьев и ошибку oob для моего RandomForestRegresser и GradietBoostRegressor. Поэтому я закодировал эти строки, но по какой-то причине объект '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