Hướng dẫn sensitivity analysis python sklearn - phân tích độ nhạy python sklearn

Mục tiêu của các phương pháp hòa tấu là kết hợp các dự đoán của một số công cụ ước tính cơ sở được xây dựng với một thuật toán học tập nhất định để cải thiện tính tổng quát / mạnh mẽ so với một công cụ ước tính duy nhất.ensemble methods is to combine the predictions of several base estimators built with a given learning algorithm in order to improve generalizability / robustness over a single estimator.

Hai gia đình của các phương pháp hòa tấu thường được phân biệt:

  • Trong các phương pháp trung bình, nguyên tắc lái xe là xây dựng một số công cụ ước tính một cách độc lập và sau đó để trung bình dự đoán của họ. Trung bình, công cụ ước tính kết hợp thường tốt hơn bất kỳ công cụ ước tính cơ sở nào vì phương sai của nó bị giảm.averaging methods, the driving principle is to build several estimators independently and then to average their predictions. On average, the combined estimator is usually better than any of the single base estimator because its variance is reduced.

    Ví dụ: Phương pháp đóng gói, rừng cây ngẫu nhiên, Bagging methods, Forests of randomized trees, …

  • Ngược lại, trong các phương pháp tăng cường, các công cụ ước tính cơ sở được xây dựng tuần tự và người ta cố gắng giảm sự thiên vị của công cụ ước tính kết hợp. Động lực là kết hợp một số mô hình yếu để tạo ra một bộ đồng phục mạnh mẽ.boosting methods, base estimators are built sequentially and one tries to reduce the bias of the combined estimator. The motivation is to combine several weak models to produce a powerful ensemble.

    Ví dụ: Adaboost, Gradient Tree Boosting, AdaBoost, Gradient Tree Boosting, …

1.11.1. Gói meta-estimator¶Bagging meta-estimator¶

Trong các thuật toán hòa tấu, các phương thức đóng gói tạo thành một lớp thuật toán xây dựng một số trường hợp của công cụ ước tính hộp đen trên các tập hợp ngẫu nhiên của tập huấn luyện ban đầu và sau đó tổng hợp các dự đoán riêng lẻ của chúng để hình thành dự đoán cuối cùng. Các phương pháp này được sử dụng như một cách để giảm phương sai của công cụ ước tính cơ sở [ví dụ: cây quyết định], bằng cách đưa ngẫu nhiên vào quy trình xây dựng của nó và sau đó tạo ra một bản hòa tấu từ nó. Trong nhiều trường hợp, các phương pháp đóng gói tạo thành một cách rất đơn giản để cải thiện đối với một mô hình duy nhất, mà không cần thiết phải điều chỉnh thuật toán cơ sở cơ bản. Vì họ cung cấp một cách để giảm quá mức, các phương pháp đóng gói hoạt động tốt nhất với các mô hình mạnh mẽ và phức tạp [ví dụ: cây quyết định được phát triển đầy đủ], trái ngược với các phương pháp tăng cường thường hoạt động tốt nhất với các mô hình yếu [ví dụ: cây quyết định nông].

Phương pháp đóng gói có nhiều hương vị nhưng chủ yếu khác nhau bởi cách chúng vẽ các tập hợp ngẫu nhiên của tập huấn luyện:

  • Khi các tập hợp ngẫu nhiên của bộ dữ liệu được vẽ dưới dạng các tập hợp ngẫu nhiên của các mẫu, thì thuật toán này được gọi là dán [B1999].[B1999].

  • Khi các mẫu được rút ra bằng sự thay thế, thì phương pháp này được gọi là đóng gói [B1996].[B1996].

  • Khi các tập hợp ngẫu nhiên của bộ dữ liệu được vẽ dưới dạng các tập hợp ngẫu nhiên của các tính năng, thì phương thức được gọi là không gian con ngẫu nhiên [H1998].[H1998].

  • Cuối cùng, khi các công cụ ước tính cơ sở được xây dựng trên các tập hợp con của cả hai mẫu và tính năng, thì phương pháp này được gọi là các bản vá ngẫu nhiên [LG2012].[LG2012].

Trong Scikit-LEARN, các phương thức đóng gói được cung cấp dưới dạng

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
7 Meta-estimator thống nhất [tương ứng
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
8], lấy đầu vào một công cụ ước tính cơ sở do người dùng chỉ định cùng với các tham số chỉ định chiến lược để vẽ các tập hợp ngẫu nhiên. Cụ thể,
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
9 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
0 kiểm soát kích thước của các tập hợp con [theo các mẫu và tính năng], trong khi
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
1 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
2 kiểm soát xem các mẫu và tính năng có được rút ra có hoặc không có thay thế. Khi sử dụng một tập hợp con của các mẫu có sẵn, độ chính xác tổng quát có thể được ước tính với các mẫu ngoài túi bằng cách đặt
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
3. Ví dụ, đoạn trích bên dưới minh họa cách khởi tạo một bộ đồng bộ đóng gói của các công cụ ước tính cơ sở
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
4, mỗi bộ được xây dựng trên các tập hợp ngẫu nhiên của 50% mẫu và 50% các tính năng.

>>> from sklearn.ensemble import BaggingClassifier
>>> from sklearn.neighbors import KNeighborsClassifier
>>> bagging = BaggingClassifier[KNeighborsClassifier[],
...                             max_samples=0.5, max_features=0.5]

1.11.2. Rừng cây ngẫu nhiênForests of randomized trees¶

Mô-đun

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
5 bao gồm hai thuật toán trung bình dựa trên các cây quyết định ngẫu nhiên: thuật toán ngẫu nhiên và phương thức thực tế. Cả hai thuật toán là các kỹ thuật nhiễu loạn và chiến đấu [B1998] được thiết kế đặc biệt cho cây. Điều này có nghĩa là một tập hợp các phân loại đa dạng được tạo ra bằng cách giới thiệu tính ngẫu nhiên trong cấu trúc phân loại. Dự đoán của nhóm được đưa ra như là dự đoán trung bình của các phân loại riêng lẻ.decision trees: the RandomForest algorithm and the Extra-Trees method. Both algorithms are perturb-and-combine techniques [B1998] specifically designed for trees. This means a diverse set of classifiers is created by introducing randomness in the classifier construction. The prediction of the ensemble is given as the averaged prediction of the individual classifiers.

Là các phân loại khác, các phân loại rừng phải được trang bị hai mảng: một mảng x thưa hoặc dày đặc x của hình

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
6 giữ các mẫu đào tạo và một mảng y có hình dạng
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
7 giữ các giá trị mục tiêu [nhãn lớp] cho các mẫu đào tạo:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]

Giống như cây quyết định, rừng cây cũng mở rộng đến các vấn đề đa sản lượng [nếu y là một loạt hình dạng

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
8].decision trees, forests of trees also extend to multi-output problems [if Y is an array of shape
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
8].

1.11.2.1. Rừng ngẫu nhiênRandom Forests¶

Trong các khu rừng ngẫu nhiên [xem các lớp

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
9 và
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
0], mỗi cây trong bộ đồng phục được xây dựng từ một mẫu được rút ra với sự thay thế [tức là, một mẫu bootstrap] từ bộ huấn luyện.

Hơn nữa, khi tách từng nút trong quá trình xây dựng một cây, sự phân chia tốt nhất được tìm thấy từ tất cả các tính năng đầu vào hoặc một tập hợp con ngẫu nhiên có kích thước

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
0. [Xem Hướng dẫn điều chỉnh tham số để biết thêm chi tiết].parameter tuning guidelines for more details].

Mục đích của hai nguồn ngẫu nhiên này là làm giảm phương sai của công cụ ước tính rừng. Thật vậy, các cây quyết định cá nhân thường thể hiện phương sai cao và có xu hướng vượt quá. Sự ngẫu nhiên được tiêm trong rừng mang lại những cây quyết định có lỗi dự đoán hơi tách rời. Bằng cách lấy trung bình những dự đoán đó, một số lỗi có thể hủy bỏ. Rừng ngẫu nhiên đạt được phương sai giảm bằng cách kết hợp các cây khác nhau, đôi khi với chi phí tăng nhẹ về sai lệch. Trong thực tế, việc giảm phương sai thường là đáng kể do đó mang lại một mô hình tổng thể tốt hơn.

In contrast to the original publication [B2001], the scikit-learn implementation combines classifiers by averaging their probabilistic prediction, instead of letting each classifier vote for a single class.

1.11.2.2. Extremely Randomized Trees¶

In extremely randomized trees [see

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
2 and
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
3 classes], randomness goes one step further in the way splits are computed. As in random forests, a random subset of candidate features is used, but instead of looking for the most discriminative thresholds, thresholds are drawn at random for each candidate feature and the best of these randomly-generated thresholds is picked as the splitting rule. This usually allows to reduce the variance of the model a bit more, at the expense of a slightly greater increase in bias:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True

1.11.2.3. Parameters¶

The main parameters to adjust when using these methods is

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 and
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
0. The former is the number of trees in the forest. The larger the better, but also the longer it will take to compute. In addition, note that results will stop getting significantly better beyond a critical number of trees. The latter is the size of the random subsets of features to consider when splitting a node. The lower the greater the reduction of variance, but also the greater the increase in bias. Empirical good default values are
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
6 or equivalently
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
7 [always considering all features instead of a random subset] for regression problems, and
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
8 [using a random subset of size
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
9] for classification tasks [where
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
0 is the number of features in the data]. The default value of
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
6 is equivalent to bagged trees and more randomness can be achieved by setting smaller values [e.g. 0.3 is a typical default in the literature]. Good results are often achieved when setting
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
2 in combination with
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
3 [i.e., when fully developing the trees]. Bear in mind though that these values are usually not optimal, and might result in models that consume a lot of RAM. The best parameter values should always be cross-validated. In addition, note that in random forests, bootstrap samples are used by default [
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
4] while the default strategy for extra-trees is to use the whole dataset [
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
5]. When using bootstrap sampling the generalization error can be estimated on the left out or out-of-bag samples. This can be enabled by setting
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
3.

Note

The size of the model with the default parameters is \[O[ M * N * log [N] ]\], where \[M\] is the number of trees and \[N\] is the number of samples. In order to reduce the size of the model, you can change these parameters:

>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
7,
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8,
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
9 and
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
0.

1.11.2.4. Parallelization¶

Finally, this module also features the parallel construction of the trees and the parallel computation of the predictions through the

>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
1 parameter. If
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
2 then computations are partitioned into
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3 jobs, and run on
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3 cores of the machine. If
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
5 then all cores available on the machine are used. Note that because of inter-process communication overhead, the speedup might not be linear [i.e., using
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3 jobs will unfortunately not be
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3 times as fast]. Significant speedup can still be achieved though when building a large number of trees, or when building a single tree requires a fair amount of time [e.g., on large datasets].

1.11.2.5. Feature importance evaluation¶

The relative rank [i.e. depth] of a feature used as a decision node in a tree can be used to assess the relative importance of that feature with respect to the predictability of the target variable. Features used at the top of the tree contribute to the final prediction decision of a larger fraction of the input samples. The expected fraction of the samples they contribute to can thus be used as an estimate of the relative importance of the features. In scikit-learn, the fraction of samples a feature contributes to is combined with the decrease in impurity from splitting them to create a normalized estimate of the predictive power of that feature.

By averaging the estimates of predictive ability over several randomized trees one can reduce the variance of such an estimate and use it for feature selection. This is known as the mean decrease in impurity, or MDI. Refer to [L2014] for more information on MDI and feature importance evaluation with Random Forests.

Warning

The impurity-based feature importances computed on tree-based models suffer from two flaws that can lead to misleading conclusions. First they are computed on statistics derived from the training dataset and therefore do not necessarily inform us on which features are most important to make good predictions on held-out dataset. Secondly, they favor high cardinality features, that is features with many unique values. Permutation feature importance is an alternative to impurity-based feature importance that does not suffer from these flaws. These two methods of obtaining feature importance are explored in: Permutation Importance vs Random Forest Feature Importance [MDI].

Ví dụ sau đây cho thấy một biểu diễn được mã hóa màu của tầm quan trọng tương đối của từng pixel riêng lẻ cho một tác vụ nhận dạng khuôn mặt bằng mô hình

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
2.

Trong thực tế, các ước tính này được lưu trữ dưới dạng thuộc tính có tên

>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
9 trên mô hình được trang bị. Đây là một mảng có hình
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
0 có giá trị dương và tổng lên 1.0. Giá trị càng cao, càng quan trọng là sự đóng góp của tính năng phù hợp cho hàm dự đoán.

1.11.2.6. Hoàn toàn ngẫu nhiên cây nhúngTotally Random Trees Embedding¶

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
1 thực hiện một sự chuyển đổi không giám sát của dữ liệu. Sử dụng một khu rừng của các cây hoàn toàn ngẫu nhiên,
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
1 mã hóa dữ liệu bằng các chỉ số của Lá một điểm dữ liệu kết thúc. Chỉ số này sau đó được mã hóa theo cách độc đáo của K, dẫn đến mã hóa nhị phân có chiều cao, thưa thớt. Mã hóa này có thể được tính toán rất hiệu quả và sau đó có thể được sử dụng làm cơ sở cho các nhiệm vụ học tập khác. Kích thước và độ thưa của mã có thể bị ảnh hưởng bằng cách chọn số lượng cây và độ sâu tối đa trên mỗi cây. Đối với mỗi cây trong bộ đồng phục, mã hóa chứa một mục của một. Kích thước của mã hóa nhiều nhất là
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
3, số lượng lá tối đa trong rừng.

Vì các điểm dữ liệu lân cận có nhiều khả năng nằm trong cùng một lá của một cây, việc chuyển đổi thực hiện ước tính mật độ ngầm, không tham số.

Xem thêm

Các kỹ thuật học tập đa dạng cũng có thể hữu ích để rút ra các biểu diễn phi tuyến tính của không gian tính năng, các phương pháp này cũng tập trung vào giảm kích thước. techniques can also be useful to derive non-linear representations of feature space, also these approaches focus also on dimensionality reduction.

1.11.3. Adaboost¶AdaBoost¶

Mô -đun

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
5 bao gồm thuật toán tăng cường phổ biến ADABOOST, được giới thiệu vào năm 1995 bởi Freund và Schapire [FS1995].[FS1995].

Nguyên tắc cốt lõi của Adaboost là phù hợp với một chuỗi những người học yếu [nghĩa là, các mô hình chỉ tốt hơn một chút so với việc đoán ngẫu nhiên, chẳng hạn như cây quyết định nhỏ] trên các phiên bản dữ liệu được sửa đổi nhiều lần. Các dự đoán từ tất cả chúng sau đó được kết hợp thông qua một cuộc bỏ phiếu đa số [hoặc tổng] có trọng số để đưa ra dự đoán cuối cùng. Các sửa đổi dữ liệu tại mỗi lần được gọi là lần lặp tăng cường bao gồm áp dụng các trọng số \ [w_1 \], \ [w_2 \], Hồi, \ [w_n \] cho mỗi mẫu đào tạo. Ban đầu, các trọng số đó đều được đặt thành \ [w_i = 1/n \], do đó bước đầu tiên chỉ cần đào tạo một người học yếu trên dữ liệu gốc. Đối với mỗi lần lặp liên tiếp, các trọng số mẫu được sửa đổi riêng lẻ và thuật toán học tập được áp dụng lại cho dữ liệu được xem xét lại. Ở một bước nhất định, những ví dụ đào tạo được dự đoán không chính xác bởi mô hình được tăng cường gây ra ở bước trước có trọng số của chúng tăng lên, trong khi trọng lượng giảm cho những người được dự đoán chính xác. Khi các lần lặp lại, các ví dụ khó dự đoán nhận được ảnh hưởng ngày càng tăng. Do đó, mỗi người học yếu sau đó bị buộc phải tập trung vào các ví dụ bị bỏ qua bởi những người trước đó trong chuỗi [HTF].\[w_1\], \[w_2\], …, \[w_N\] to each of the training samples. Initially, those weights are all set to \[w_i = 1/N\], so that the first step simply trains a weak learner on the original data. For each successive iteration, the sample weights are individually modified and the learning algorithm is reapplied to the reweighted data. At a given step, those training examples that were incorrectly predicted by the boosted model induced at the previous step have their weights increased, whereas the weights are decreased for those that were predicted correctly. As iterations proceed, examples that are difficult to predict receive ever-increasing influence. Each subsequent weak learner is thereby forced to concentrate on the examples that are missed by the previous ones in the sequence [HTF].

Adaboost có thể được sử dụng cả cho các vấn đề phân loại và hồi quy:

  • Để phân loại nhiều lớp,

    >>> from sklearn.datasets import make_hastie_10_2
    >>> from sklearn.ensemble import GradientBoostingClassifier
    
    >>> X, y = make_hastie_10_2[random_state=0]
    >>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
    ...     max_depth=1, random_state=0].fit[X, y]
    >>> clf.feature_importances_
    array[[0.10..., 0.10..., 0.11..., ...
    
    5 thực hiện Adaboost-Samme và Adaboost-Samme.R [ZZRH2009].[ZZRH2009].

  • Đối với hồi quy,

    >>> from sklearn.datasets import make_hastie_10_2
    >>> from sklearn.ensemble import GradientBoostingClassifier
    
    >>> X, y = make_hastie_10_2[random_state=0]
    >>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
    ...     max_depth=1, random_state=0].fit[X, y]
    >>> clf.feature_importances_
    array[[0.10..., 0.10..., 0.11..., ...
    
    6 thực hiện adaboost.r2 [d1997].[D1997].

1.11.3.1. Cách sử dụng¶Usage¶

Ví dụ sau đây cho thấy cách phù hợp với trình phân loại Adaboost với 100 người học yếu:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...

Số lượng người học yếu được kiểm soát bởi tham số

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4. Tham số
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 kiểm soát sự đóng góp của những người học yếu trong kết hợp cuối cùng. Theo mặc định, người học yếu là gốc cây quyết định. Những người học yếu khác nhau có thể được chỉ định thông qua tham số
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
9. Các tham số chính để điều chỉnh để thu được kết quả tốt là
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 và độ phức tạp của các công cụ ước tính cơ sở [ví dụ: độ sâu
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
9 hoặc số mẫu cần thiết tối thiểu để xem xét phân chia
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
7].

1.11.4. Cây gradient tăng cườngGradient Tree Boosting¶

Cây gradient tăng cường hoặc độ dốc tăng cường các cây quyết định [GBDT] là một khái quát của việc tăng cường các chức năng tổn thất khác biệt tùy ý, xem công việc tinh dịch của [Friedman2001]. GBDT là một thủ tục chính xác và hiệu quả, có thể được sử dụng cho cả các vấn đề hồi quy và phân loại trong nhiều lĩnh vực bao gồm xếp hạng tìm kiếm trên web và sinh thái học.[Friedman2001]. GBDT is an accurate and effective off-the-shelf procedure that can be used for both regression and classification problems in a variety of areas including Web search ranking and ecology.

Mô -đun

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
5 cung cấp các phương pháp cho cả phân loại và hồi quy thông qua các cây quyết định được tăng cường độ dốc.

Việc sử dụng và các tham số của

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 được mô tả dưới đây. 2 tham số quan trọng nhất của các công cụ ước tính này là
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 và
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8.

1.11.4.1. Phân loại %Classification¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 hỗ trợ cả phân loại nhị phân và đa lớp. Ví dụ sau đây cho thấy cách phù hợp với bộ phân loại tăng gradient với 100 gốc quyết định là người học yếu:

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...

Số lượng người học yếu [tức là cây hồi quy] được kiểm soát bởi tham số

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4; Kích thước của mỗi cây có thể được điều khiển bằng cách đặt độ sâu của cây thông qua
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
9 hoặc bằng cách đặt số lượng nút lá thông qua
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8.
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 là một tham số siêu trong phạm vi [0,0, 1.0] kiểm soát quá mức thông qua co rút.The size of each tree can be controlled either by setting the tree depth via
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
9 or by setting the number of leaf nodes via
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8. The
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 is a hyper-parameter in the range [0.0, 1.0] that controls overfitting via shrinkage .

Ghi chú

Phân loại với hơn 2 lớp yêu cầu cảm ứng của cây hồi quy

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
3 tại mỗi lần lặp, do đó, tổng số cây gây ra bằng
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
4. Đối với các bộ dữ liệu có số lượng lớn các lớp, chúng tôi khuyên bạn nên sử dụng
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 thay thế cho
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4.

1.11.4.2. Hồi quy¶Regression¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 hỗ trợ một số chức năng tổn thất khác nhau cho hồi quy có thể được chỉ định thông qua đối số
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
8; Hàm mất mặc định cho hồi quy là lỗi bình phương [
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
9].different loss functions for regression which can be specified via the argument
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
8; the default loss function for regression is squared error [
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
9].

>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...

Hình dưới đây cho thấy kết quả áp dụng

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 với mất bình phương tối thiểu và 500 người học cơ sở cho bộ dữ liệu bệnh tiểu đường [
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
01]. Cốt truyện cho thấy lỗi tàu và thử nghiệm tại mỗi lần lặp. Lỗi tàu tại mỗi lần lặp được lưu trữ trong thuộc tính ____102 của mô hình tăng gradient. Lỗi kiểm tra ở mỗi lần lặp có thể thu được thông qua phương thức
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
03 trả về một trình tạo mang lại dự đoán ở mỗi giai đoạn. Các lô như thế này có thể được sử dụng để xác định số lượng cây tối ưu [nghĩa là
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4] bằng cách dừng sớm.

1.11.4.3. Phù hợp với những người học yếu kém hơnFitting additional weak-learners¶

Cả hỗ trợ

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
07 cho phép bạn thêm nhiều công cụ ước tính vào một mô hình đã được trang bị.

>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...

1.11.4.4. Kiểm soát kích thước câyControlling the tree size¶

Kích thước của người học cơ sở cây hồi quy xác định mức độ tương tác biến có thể được ghi lại bằng mô hình tăng độ dốc. Nói chung, một cây có độ sâu

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
08 có thể nắm bắt các tương tác của trật tự
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
08. Có hai cách trong đó kích thước của các cây hồi quy riêng lẻ có thể được kiểm soát.

Nếu bạn chỉ định

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
10 thì hoàn thành các cây nhị phân có độ sâu
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
08 sẽ được trồng. Những cây như vậy sẽ có [nhiều nhất]
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
12 các nút lá và các nút phân tách
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
13.

Ngoài ra, bạn có thể kiểm soát kích thước cây bằng cách chỉ định số lượng nút lá thông qua tham số

>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8. Trong trường hợp này, cây sẽ được trồng bằng cách sử dụng tìm kiếm đầu tiên tốt nhất trong đó các nút có sự cải thiện cao nhất trong tạp chất sẽ được mở rộng trước. Một cây có
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
15 có các nút phân tách
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
16 và do đó có thể mô hình hóa các tương tác lên để đặt hàng
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
17.

Chúng tôi thấy rằng

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
15 cho kết quả tương đương với
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
19 nhưng nhanh hơn đáng kể để đào tạo với chi phí của một lỗi đào tạo cao hơn một chút. Tham số
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8 tương ứng với biến
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
21 trong chương về tăng gradient trong [Friedman2001] và có liên quan đến tham số
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
22 trong gói Riên GBM trong đó
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
23.[Friedman2001] and is related to the parameter
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
22 in R’s gbm package where
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
23 .

1.11.4.5. Công thức toán họcMathematical formulation¶

Đầu tiên chúng tôi trình bày GBRT cho hồi quy, và sau đó chi tiết trường hợp phân loại.

1.11.4.5.1. Hồi quy¶Regression¶

Các hồi quy GBRT là các mô hình phụ gia có dự đoán \ [\ hat {y} _i \] cho một đầu vào đã cho \ [x_i \] có dạng sau:\[\hat{y}_i\] for a given input \[x_i\] is of the following form:

\ [\ hat {y} _i = f_m [x_i] = \ sum_ {m = 1}^{m} h_m [x_i] \]

trong đó \ [h_m \] là những người ước tính được gọi là người học yếu trong bối cảnh tăng cường. Cây gradient tăng cường sử dụng các hồi quy cây quyết định có kích thước cố định như người học yếu. Hằng số m tương ứng với tham số

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4.\[h_m\] are estimators called weak learners in the context of boosting. Gradient Tree Boosting uses decision tree regressors of fixed size as weak learners. The constant M corresponds to the
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 parameter.

Tương tự như các thuật toán tăng cường khác, GBRT được xây dựng theo kiểu tham lam:

\ [F_m [x] = f_ {m-1} [x] + h_m [x], \]

trong đó cây mới được thêm vào \ [h_m \] được trang bị để giảm thiểu một tổng tổn thất \ [l_m \], được đưa ra trước đó \ [f_ {m-1} \]:\[h_m\] is fitted in order to minimize a sum of losses \[L_m\], given the previous ensemble \[F_{m-1}\]:

\] , \]

trong đó \ [l [y_i, f [x_i]] \] được xác định bởi tham số

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
8, chi tiết trong phần tiếp theo.\[l[y_i, F[x_i]]\] is defined by the
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
8 parameter, detailed in the next section.

Theo mặc định, mô hình ban đầu \ [f_ {0} \] được chọn làm hằng số giảm thiểu tổn thất: đối với tổn thất bình phương nhỏ nhất, đây là giá trị trung bình theo kinh nghiệm của các giá trị đích. Mô hình ban đầu cũng có thể được chỉ định thông qua đối số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
26.\[F_{0}\] is chosen as the constant that minimizes the loss: for a least-squares loss, this is the empirical mean of the target values. The initial model can also be specified via the
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
26 argument.

Sử dụng xấp xỉ Taylor bậc nhất, giá trị của \ [l \] có thể được xấp xỉ như sau:\[l\] can be approximated as follows:

\ [l [y_i, f_ {m-1} [x_i] + h_m [x_i]] \ xấp xỉ l [y_i, f_ {m-1} [x_i]] l [y_i, f [x_i]]} {\ partial f [x_i]} \ right] _ {f = f_ {m - 1}}. \]

Ghi chú

Tóm lại, một xấp xỉ Taylor bậc nhất nói rằng \ [l [z] \ xấp xỉ l [a] + [z - a] \ frac {\ partial l [a]} {\ part a} \]. Ở đây, \ [z \] tương ứng với \ [f_ {m - 1} [x_i] + h_m [x_i] \] và \ [a \] tương ứng với \ [f_ {m -1} [x_i] \]\[l[z] \approx l[a] + [z - a] \frac{\partial l[a]}{\partial a}\]. Here, \[z\] corresponds to \[F_{m - 1}[x_i] + h_m[x_i]\], and \[a\] corresponds to \[F_{m-1}[x_i]\]

Số lượng \ [\ left [\ frac {\ partial l [y_i, f [x_i]]} {\ partial f [x_i]} \ right] Mất mát đối với tham số thứ hai của nó, được đánh giá tại \ [f_ {m-1} [x] \]. Thật dễ dàng để tính toán cho bất kỳ \ [f_ {m - 1} [x_i] \] đã cho ở dạng đóng vì tổn thất là khác biệt. Chúng tôi sẽ biểu thị nó bằng \ [g_i \].\[\left[ \frac{\partial l[y_i, F[x_i]]}{\partial F[x_i]} \right]_{F=F_{m - 1}}\] is the derivative of the loss with respect to its second parameter, evaluated at \[F_{m-1}[x]\]. It is easy to compute for any given \[F_{m - 1}[x_i]\] in a closed form since the loss is differentiable. We will denote it by \[g_i\].

Loại bỏ các thuật ngữ không đổi, chúng tôi có:

\ [h_m \ xấp xỉ \ arg \ min_ {h} \ sum_ {i = 1}^{n} h [x_i]

Điều này được giảm thiểu nếu \ [h [x_i] \] được trang bị để dự đoán một giá trị tỷ lệ thuận với gradient âm \ [-g_i \]. Do đó, tại mỗi lần lặp, công cụ ước tính \ [h_m \] được trang bị để dự đoán độ dốc âm của các mẫu. Các gradient được cập nhật tại mỗi lần lặp. Điều này có thể được coi là một loại giảm độ dốc trong một không gian chức năng.\[h[x_i]\] is fitted to predict a value that is proportional to the negative gradient \[-g_i\]. Therefore, at each iteration, the estimator \[h_m\] is fitted to predict the negative gradients of the samples. The gradients are updated at each iteration. This can be considered as some kind of gradient descent in a functional space.

Ghi chú

Đối với một số tổn thất, ví dụ: Độ lệch tuyệt đối nhất [LAD] trong đó độ dốc là \ [\ pm 1 \], các giá trị được dự đoán bởi một \ [h_m \] được trang bị không đủ chính xác: cây chỉ có thể xuất các giá trị nguyên. Kết quả là, các giá trị lá của cây \ [h_m \] được sửa đổi một khi cây được trang bị, sao cho các giá trị lá giảm thiểu tổn thất \ [l_m \]. Bản cập nhật phụ thuộc vào mất mát: đối với việc mất LAD, giá trị của một chiếc lá được cập nhật lên trung vị của các mẫu trong chiếc lá đó.\[\pm 1\], the values predicted by a fitted \[h_m\] are not accurate enough: the tree can only output integer values. As a result, the leaves values of the tree \[h_m\] are modified once the tree is fitted, such that the leaves values minimize the loss \[L_m\]. The update is loss-dependent: for the LAD loss, the value of a leaf is updated to the median of the samples in that leaf.

1.11.4.5.2. Phân loại %Classification¶

Gradient tăng cường để phân loại rất giống với trường hợp hồi quy. Tuy nhiên, tổng của các cây \ [f_m [x_i] = \ sum_m h_m [x_i] \] không đồng nhất với dự đoán: nó không thể là một lớp, vì các cây dự đoán các giá trị liên tục.\[F_M[x_i] = \sum_m h_m[x_i]\] is not homogeneous to a prediction: it cannot be a class, since the trees predict continuous values.

Ánh xạ từ giá trị \ [f_m [x_i] \] đến một lớp hoặc xác suất phụ thuộc vào mất. Đối với mất log, xác suất \ [x_i \] thuộc lớp dương được mô hình hóa là \ [p [y_i = 1 | x_i] = \ sigma [f_m [x_i]] \] trong đó \ [\ sigma \] là chức năng sigmoid hoặc expit.\[F_M[x_i]\] to a class or a probability is loss-dependent. For the log-loss, the probability that \[x_i\] belongs to the positive class is modeled as \[p[y_i = 1 | x_i] = \sigma[F_M[x_i]]\] where \[\sigma\] is the sigmoid or expit function.

Để phân loại đa lớp, các cây K [đối với các lớp K] được xây dựng tại mỗi lần lặp \ [M \]. Xác suất \ [x_i \] thuộc lớp K được mô hình hóa dưới dạng các giá trị mềm của \ [f_ {m, k} [x_i] \].\[M\] iterations. The probability that \[x_i\] belongs to class k is modeled as a softmax of the \[F_{M,k}[x_i]\] values.

Lưu ý rằng ngay cả đối với một tác vụ phân loại, Trình ước tính phụ \ [H_M \] vẫn là một bộ phân loại, không phải là một trình phân loại. Điều này là do các chuyên gia phụ được đào tạo để dự đoán độ dốc [âm], luôn luôn là số lượng liên tục.\[h_m\] sub-estimator is still a regressor, not a classifier. This is because the sub-estimators are trained to predict [negative] gradients, which are always continuous quantities.

1.11.4.6. Chức năng mấtLoss Functions¶

Các chức năng tổn thất sau được hỗ trợ và có thể được chỉ định bằng tham số

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
8:

  • hồi quy

    • Lỗi bình phương [

      >>> from sklearn.ensemble import HistGradientBoostingClassifier
      >>> import numpy as np
      
      >>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
      >>> y = [0, 0, 1, 1]
      
      >>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
      >>> gbdt.predict[X]
      array[[0, 0, 1, 1]]
      
      9]: Sự lựa chọn tự nhiên cho hồi quy do các thuộc tính tính toán vượt trội của nó. Mô hình ban đầu được đưa ra bởi giá trị trung bình của các giá trị đích.

    • Độ lệch tuyệt đối nhất [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      29]: Chức năng mất mạnh cho hồi quy. Mô hình ban đầu được đưa ra bởi trung bình của các giá trị mục tiêu.

    • Huber [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      30]: Một chức năng tổn thất mạnh mẽ khác kết hợp bình phương tối thiểu và độ lệch ít nhất tuyệt đối; Sử dụng
      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      31 để kiểm soát độ nhạy liên quan đến các ngoại lệ [xem [Friedman2001] để biết thêm chi tiết].[Friedman2001] for more details].

    • Quantile [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      32]: Hàm mất cho hồi quy lượng tử. Sử dụng
      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      33 để chỉ định lượng tử. Hàm mất này có thể được sử dụng để tạo khoảng thời gian dự đoán [xem các khoảng dự đoán để hồi quy tăng độ dốc].Prediction Intervals for Gradient Boosting Regression].

  • Phân loại

    • Lỗ thua log nhị phân [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      34]: Chức năng mất khả năng log âm nhị phân nhị phân để phân loại nhị phân. Nó cung cấp ước tính xác suất. Mô hình ban đầu được đưa ra bởi tỷ lệ cược log.

    • Lỗ thua log đa lớp [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      34]: Chức năng mất khả năng nhật ký âm tính đa cực để phân loại đa lớp với các lớp loại trừ lẫn nhau. Nó cung cấp ước tính xác suất. Mô hình ban đầu được đưa ra bởi xác suất trước của mỗi lớp. Tại mỗi lần lặp lại, các cây hồi quy
      >>> from sklearn.ensemble import HistGradientBoostingClassifier
      >>> import numpy as np
      
      >>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
      >>> y = [0, 0, 1, 1]
      
      >>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
      >>> gbdt.predict[X]
      array[[0, 0, 1, 1]]
      
      3 phải được xây dựng, điều này làm cho GBRT khá không hiệu quả đối với các bộ dữ liệu với số lượng lớn các lớp.

    • Mất theo cấp số nhân [

      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      38]: Hàm tổn thất tương tự như
      >>> from sklearn.datasets import make_hastie_10_2
      >>> from sklearn.ensemble import GradientBoostingClassifier
      
      >>> X, y = make_hastie_10_2[random_state=0]
      >>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
      ...     max_depth=1, random_state=0].fit[X, y]
      >>> clf.feature_importances_
      array[[0.10..., 0.10..., 0.11..., ...
      
      5. Ít mạnh mẽ hơn đối với các ví dụ được dán nhãn sai so với
      >>> from sklearn.ensemble import RandomForestClassifier
      >>> X = [[0, 0], [1, 1]]
      >>> Y = [0, 1]
      >>> clf = RandomForestClassifier[n_estimators=10]
      >>> clf = clf.fit[X, Y]
      
      34; Chỉ có thể được sử dụng để phân loại nhị phân.

1.11.4.7. Co ngót qua tỷ lệ học tậpShrinkage via learning rate¶

[Friedman2001] đã đề xuất một chiến lược chính quy đơn giản làm cho sự đóng góp của mỗi người học yếu theo một yếu tố không đổi \ [\ nu \]: proposed a simple regularization strategy that scales the contribution of each weak learner by a constant factor \[\nu\]:

\ [F_m [x] = f_ {m-1} [x] + \ nu h_m [x] \]

Tham số \ [\ nu \] còn được gọi là tốc độ học tập vì nó mở rộng chiều dài của thủ tục giảm độ dốc; Nó có thể được đặt thông qua tham số

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8.\[\nu\] is also called the learning rate because it scales the step length the gradient descent procedure; it can be set via the
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 parameter.

Tham số

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 tương tác mạnh mẽ với tham số
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4, số lượng người học yếu để phù hợp. Các giá trị nhỏ hơn của
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 yêu cầu số lượng lớn hơn người học yếu để duy trì lỗi đào tạo liên tục. Bằng chứng thực nghiệm cho thấy các giá trị nhỏ của
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 ủng hộ lỗi kiểm tra tốt hơn. [HTF] khuyên bạn nên đặt tỷ lệ học tập thành một hằng số nhỏ [ví dụ:
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
46] và chọn
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 bằng cách dừng sớm. Để thảo luận chi tiết hơn về sự tương tác giữa
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 và
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4, hãy xem [R2007].[HTF] recommend to set the learning rate to a small constant [e.g.
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
46] and choose
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 by early stopping. For a more detailed discussion of the interaction between
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...
8 and
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 see [R2007].

1.11.4.8. Mẫu conSubsampling¶

[Friedman2002] đề xuất tăng gradient ngẫu nhiên, kết hợp tăng gradient với trung bình bootstrap [đóng gói]. Tại mỗi lần lặp, trình phân loại cơ sở được đào tạo trên một phân số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
50 của dữ liệu đào tạo có sẵn. Các mẫu phụ được rút ra mà không cần thay thế. Một giá trị điển hình của
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
50 là 0,5. proposed stochastic gradient boosting, which combines gradient boosting with bootstrap averaging [bagging]. At each iteration the base classifier is trained on a fraction
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
50 of the available training data. The subsample is drawn without replacement. A typical value of
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
50 is 0.5.

Hình dưới đây minh họa ảnh hưởng của co rút và lấy mẫu đối với độ phù hợp của mô hình. Chúng ta có thể thấy rõ rằng sự co ngót vượt trội so với không có. Việc lấy mẫu với co rút có thể làm tăng thêm độ chính xác của mô hình. Mặt khác, việc lấy mẫu mà không co rút, làm kém.

Một chiến lược khác để giảm phương sai là sử dụng các tính năng tương tự như các phân tách ngẫu nhiên trong

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
9. Số lượng các tính năng được mẫu phụ có thể được kiểm soát thông qua tham số
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
0.

Ghi chú

Sử dụng giá trị

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import load_iris
>>> from sklearn.ensemble import AdaBoostClassifier

>>> X, y = load_iris[return_X_y=True]
>>> clf = AdaBoostClassifier[n_estimators=100]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.9...
0 nhỏ có thể làm giảm đáng kể thời gian chạy.

Tăng cường độ dốc ngẫu nhiên cho phép tính toán các ước tính ngoài túi của độ lệch kiểm tra bằng cách tính toán sự cải thiện độ lệch trên các ví dụ không được bao gồm trong mẫu bootstrap [nghĩa là các ví dụ ngoài túi]. Các cải tiến được lưu trữ trong thuộc tính

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
55.
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
56 tổ chức cải thiện về mức lỗ trên các mẫu OOB nếu bạn thêm giai đoạn thứ i vào các dự đoán hiện tại. Các ước tính ngoài túi có thể được sử dụng để lựa chọn mô hình, ví dụ để xác định số lần lặp tối ưu. Ước tính OOB thường rất bi quan, do đó chúng tôi khuyên bạn nên sử dụng xác thực chéo và chỉ sử dụng OOB nếu xác thực chéo quá tốn thời gian.

1.11.4.9. Giải thích với Tính năng Tầm quan trọngInterpretation with feature importance¶

Cây quyết định cá nhân có thể được giải thích dễ dàng bằng cách hình dung cấu trúc cây. Tuy nhiên, các mô hình tăng cường độ dốc bao gồm hàng trăm cây hồi quy do đó chúng không thể dễ dàng giải thích bằng cách kiểm tra trực quan các cây riêng lẻ. May mắn thay, một số kỹ thuật đã được đề xuất để tóm tắt và giải thích các mô hình tăng gradient.

Thông thường các tính năng không đóng góp như nhau để dự đoán phản ứng mục tiêu; Trong nhiều tình huống, phần lớn các tính năng trên thực tế không liên quan. Khi diễn giải một mô hình, câu hỏi đầu tiên thường là: những tính năng quan trọng đó là gì và làm thế nào để chúng đóng góp trong việc dự đoán phản ứng mục tiêu là gì?

Cây quyết định cá nhân thực hiện lựa chọn tính năng bằng cách chọn các điểm phân chia thích hợp. Thông tin này có thể được sử dụng để đo lường tầm quan trọng của từng tính năng; Ý tưởng cơ bản là: một tính năng thường được sử dụng trong các điểm phân chia của một cây thì tính năng đó quan trọng hơn. Khái niệm về tầm quan trọng này có thể được mở rộng cho các bản hòa tấu của cây quyết định bằng cách lấy trung bình tầm quan trọng của tính năng dựa trên tạp chất của từng cây [xem đánh giá tầm quan trọng của tính năng để biết thêm chi tiết].Feature importance evaluation for more details].

Điểm quan trọng của tính năng của mô hình tăng độ dốc phù hợp có thể được truy cập thông qua thuộc tính

>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
9:

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X, y]
>>> clf.feature_importances_
array[[0.10..., 0.10..., 0.11..., ...

Lưu ý rằng tính toán tầm quan trọng của tính năng này dựa trên entropy và nó khác với

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
58 dựa trên hoán vị của các tính năng.

1.11.5. Boosting Gradient dựa trên biểu đồHistogram-Based Gradient Boosting¶

Scikit-learn 0,21 đã giới thiệu hai triển khai mới của cây tăng cường độ dốc, cụ thể là

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60, lấy cảm hứng từ LightGBM [xem [LightGBM]].[LightGBM]].

Các công cụ ước tính dựa trên biểu đồ này có thể là các đơn đặt hàng nhanh hơn so với

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 khi số lượng mẫu lớn hơn hàng chục ngàn mẫu.orders of magnitude faster than
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 and
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 when the number of samples is larger than tens of thousands of samples.

Họ cũng có hỗ trợ tích hợp cho các giá trị bị thiếu, điều này tránh sự cần thiết của một người yêu thích.

Các công cụ ước tính nhanh này đầu tiên thùng các mẫu đầu vào

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
63 vào các thùng có giá trị nguyên [thường là 256 thùng] làm giảm đáng kể số lượng điểm phân tách để xem xét và cho phép thuật toán tận dụng các cấu trúc dữ liệu dựa trên số nguyên [biểu đồ] giá trị khi xây dựng cây. API của các công cụ ước tính này hơi khác nhau và một số tính năng từ
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5 chưa được hỗ trợ, ví dụ như một số chức năng mất.

1.11.5.1. Cách sử dụng¶Usage¶

Hầu hết các tham số không thay đổi từ

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5. Một ngoại lệ là tham số
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
68 thay thế
>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = GradientBoostingClassifier[n_estimators=100, learning_rate=1.0,
...     max_depth=1, random_state=0].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.913...
4 và kiểm soát số lần lặp của quá trình tăng cường:

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965

Các tổn thất có sẵn cho hồi quy là ‘bình phương_error,‘ Tuyệt đối_error, ít nhạy cảm hơn với các ngoại lệ, và ‘Poisson, rất phù hợp với số lượng và tần số mô hình. Để phân loại, ‘log_loss, là tùy chọn duy nhất. Để phân loại nhị phân, nó sử dụng tổn thất nhật ký nhị phân, cũng Kown là độ lệch nhị thức hoặc phân loại chéo nhị phân. Đối với

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
70, nó sử dụng chức năng mất nhật ký đa lớp, với độ lệch đa hình và phân loại chéo phân loại làm tên thay thế. Phiên bản tổn thất thích hợp được chọn dựa trên y được thông qua để phù hợp.y passed to fit.

Kích thước của các cây có thể được kiểm soát thông qua các tham số

>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
8,
>>> import numpy as np
>>> from sklearn.metrics import mean_squared_error
>>> from sklearn.datasets import make_friedman1
>>> from sklearn.ensemble import GradientBoostingRegressor

>>> X, y = make_friedman1[n_samples=1200, random_state=0, noise=1.0]
>>> X_train, X_test = X[:200], X[200:]
>>> y_train, y_test = y[:200], y[200:]
>>> est = GradientBoostingRegressor[
...     n_estimators=100, learning_rate=0.1, max_depth=1, random_state=0,
...     loss='squared_error'
... ].fit[X_train, y_train]
>>> mean_squared_error[y_test, est.predict[X_test]]
5.00...
9 và
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
0.

Số lượng thùng được sử dụng để thùng dữ liệu được kiểm soát với tham số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
74. Sử dụng ít thùng hoạt động như một hình thức chính quy hóa. Nói chung, nó được khuyến nghị sử dụng càng nhiều thùng càng tốt, đó là mặc định.

Tham số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
75 là một quá trình chính quy về hàm mất và tương ứng với \ [\ lambda \] trong phương trình [2] của [xgboost].\[\lambda\] in equation [2] of [XGBoost].

Lưu ý rằng dừng sớm được bật theo mặc định nếu số lượng mẫu lớn hơn 10.000. Hành vi dừng sớm được kiểm soát thông qua

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
76,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
77,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
78,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
79 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
80. Có thể dừng lại sớm bằng cách sử dụng một người ghi bàn tùy ý, hoặc chỉ là việc đào tạo hoặc mất xác nhận. Lưu ý rằng vì lý do kỹ thuật, việc sử dụng người ghi bàn chậm hơn đáng kể so với việc sử dụng tổn thất. Theo mặc định, dừng sớm được thực hiện nếu có ít nhất 10.000 mẫu trong tập huấn luyện, sử dụng tổn thất xác thực.early-stopping is enabled by default if the number of samples is larger than 10,000. The early-stopping behaviour is controlled via the
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
76,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
77,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
78,
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
79, and
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
80 parameters. It is possible to early-stop using an arbitrary scorer, or just the training or validation loss. Note that for technical reasons, using a scorer is significantly slower than using the loss. By default, early-stopping is performed if there are at least 10,000 samples in the training set, using the validation loss.

1.11.5.2. Thiếu giá trị hỗ trợ BurMissing values support¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 có hỗ trợ tích hợp cho các giá trị bị thiếu [NANS].

Trong quá trình huấn luyện, người trồng cây học tại mỗi điểm phân chia cho dù các mẫu có giá trị bị thiếu sẽ đi sang trẻ trái hay phải, dựa trên mức tăng tiềm năng. Khi dự đoán, các mẫu có giá trị bị thiếu được gán cho con trái hoặc bên phải do đó:

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]

Khi mẫu thiếu được dự đoán, các phân tách có thể được thực hiện về việc liệu giá trị tính năng có bị thiếu hay không:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
0

Nếu không có giá trị bị thiếu đối với một tính năng nhất định trong quá trình đào tạo, thì các mẫu có giá trị bị thiếu được ánh xạ cho bất kỳ đứa trẻ nào có nhiều mẫu nhất.

1.11.5.3. Hỗ trợ trọng lượng mẫuSample weight support¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 Trọng lượng hỗ trợ mẫu trong quá trình phù hợp.fit.

Ví dụ đồ chơi sau đây cho thấy cách mô hình bỏ qua các mẫu có trọng số mẫu bằng không:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
1

Như bạn có thể thấy,

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
85 được phân loại thoải mái là
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
86 do hai mẫu đầu tiên bị bỏ qua do trọng lượng mẫu của chúng.

Chi tiết thực hiện: Đưa trọng lượng mẫu vào số lượng tài khoản để nhân các độ dốc [và người Hessians] với trọng số mẫu. Lưu ý rằng giai đoạn Binning [cụ thể là tính toán lượng tử] không tính đến các trọng số.

1.11.5.4. Các tính năng phân loại hỗ trợ BurCategorical Features Support¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 có hỗ trợ gốc cho các tính năng phân loại: Họ có thể xem xét các sự phân chia trên dữ liệu phân loại, không đặt hàng.

Đối với các bộ dữ liệu với các tính năng phân loại, sử dụng hỗ trợ phân loại gốc thường tốt hơn là dựa vào mã hóa một lần [

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
89], bởi vì mã hóa một lần nóng đòi hỏi độ sâu cây nhiều hơn để đạt được sự phân chia tương đương. Cũng thường tốt hơn khi dựa vào hỗ trợ phân loại gốc hơn là coi các tính năng phân loại là liên tục [thứ tự], xảy ra đối với dữ liệu phân loại được mã hóa thứ tự, vì các danh mục là số lượng danh nghĩa trong đó trật tự không quan trọng.

Để kích hoạt hỗ trợ phân loại, mặt nạ Boolean có thể được chuyển đến tham số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
90, cho biết tính năng nào là phân loại. Sau đây, tính năng đầu tiên sẽ được coi là phân loại và tính năng thứ hai là số:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
2

Tương tự, người ta có thể vượt qua danh sách các số nguyên cho biết các chỉ số của các tính năng phân loại:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
3

Tính chất của từng tính năng phân loại phải nhỏ hơn tham số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
74 và mỗi tính năng phân loại dự kiến ​​sẽ được mã hóa trong
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
92. Cuối cùng, có thể hữu ích để xử lý trước dữ liệu với
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
93 như được thực hiện trong hỗ trợ tính năng phân loại trong tăng cường độ dốc.Categorical Feature Support in Gradient Boosting.

Nếu có các giá trị bị thiếu trong quá trình đào tạo, các giá trị bị thiếu sẽ được coi là một danh mục thích hợp. Nếu không có giá trị bị thiếu trong quá trình đào tạo, thì tại thời điểm dự đoán, các giá trị bị thiếu được ánh xạ tới nút con có nhiều mẫu nhất [giống như đối với các tính năng liên tục]. Khi dự đoán, các danh mục không được nhìn thấy trong thời gian phù hợp sẽ được coi là các giá trị bị thiếu.

Phát hiện phân chia với các tính năng phân loại: Cách chính tắc xem xét các phân tách phân loại trong cây là xem xét tất cả các phân vùng \ [2^{k - 1} - 1 \], trong đó \ [k \] là số lượng của các loại. Điều này có thể nhanh chóng trở nên cấm khi \ [k \] lớn. May mắn thay, vì cây tăng cường độ dốc luôn là cây hồi quy [ngay cả đối với các vấn đề phân loại], nên tồn tại một chiến lược nhanh hơn có thể mang lại sự phân chia tương đương. Đầu tiên, các danh mục của một tính năng được sắp xếp theo phương sai của mục tiêu, cho mỗi loại

>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3. Khi các loại được sắp xếp, người ta có thể xem xét các phân vùng liên tục, tức là xử lý các loại như thể chúng được đặt hàng các giá trị liên tục [xem Fisher [Fisher1958] để biết bằng chứng chính thức]. Kết quả là, chỉ cần phải xem xét các phân tách \ [k - 1 \] thay vì \ [2^{k - 1} - 1 \]. Việc sắp xếp ban đầu là hoạt động \ [\ mathcal {o} [k \ log [k]] \], dẫn đến độ phức tạp hoàn toàn của \ [\ mathcal {o} [k \ log [k] + k] \], thay vì \ [\ mathcal {o} [2^k] \].: The canonical way of considering categorical splits in a tree is to consider all of the \[2^{K - 1} - 1\] partitions, where \[K\] is the number of categories. This can quickly become prohibitive when \[K\] is large. Fortunately, since gradient boosting trees are always regression trees [even for classification problems], there exist a faster strategy that can yield equivalent splits. First, the categories of a feature are sorted according to the variance of the target, for each category
>>> _ = est.set_params[n_estimators=200, warm_start=True]  # set warm_start and new nr of trees
>>> _ = est.fit[X_train, y_train] # fit additional 100 trees to est
>>> mean_squared_error[y_test, est.predict[X_test]]
3.84...
3. Once the categories are sorted, one can consider continuous partitions, i.e. treat the categories as if they were ordered continuous values [see Fisher [Fisher1958] for a formal proof]. As a result, only \[K - 1\] splits need to be considered instead of \[2^{K - 1} - 1\]. The initial sorting is a \[\mathcal{O}[K \log[K]]\] operation, leading to a total complexity of \[\mathcal{O}[K \log[K] + K]\], instead of \[\mathcal{O}[2^K]\].

1.11.5.5. Những hạn chế đơn điệuMonotonic Constraints¶

Tùy thuộc vào vấn đề trong tay, bạn có thể có kiến ​​thức trước đó cho thấy rằng một tính năng nhất định nói chung nên có ảnh hưởng tích cực [hoặc âm] đối với giá trị mục tiêu. Ví dụ, tất cả những người khác đều bình đẳng, điểm tín dụng cao hơn sẽ tăng khả năng được chấp thuận cho một khoản vay. Các ràng buộc đơn điệu cho phép bạn kết hợp kiến ​​thức trước đó vào mô hình.

Một ràng buộc đơn điệu tích cực là một ràng buộc của hình thức:

\ [x_1 \ leq x_1 '\ ngụ ý f [x_1, x_2] \ leq f [x_1', x_2] \], trong đó \ [f \] là yếu tố dự đoán với hai tính năng., where \[F\] is the predictor with two features.

Tương tự, một ràng buộc đơn điệu âm tính là hình thức:

\ [x_1 \ leq x_1 '\ ngụ ý f [x_1, x_2] \ geq f [x_1', x_2] \]..

Lưu ý rằng các ràng buộc đơn điệu chỉ ràng buộc đầu ra, tất cả những người khác đều bằng nhau. Thật vậy, mối quan hệ sau không được thực thi bởi một ràng buộc tích cực: \ [x_1 \ leq x_1 '\ ngụ ý f [x_1, x_2] \ leq f [x_1', x_2 '] \].is not enforced by a positive constraint: \[x_1 \leq x_1' \implies F[x_1, x_2] \leq F[x_1', x_2']\].

Bạn có thể chỉ định một ràng buộc đơn điệu trên mỗi tính năng bằng tham số

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
95. Đối với mỗi tính năng, giá trị 0 cho thấy không có ràng buộc, trong khi -1 và 1 biểu thị ràng buộc âm và tích cực, tương ứng:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
4

Trong bối cảnh phân loại nhị phân, áp đặt một ràng buộc đơn điệu có nghĩa là tính năng này được cho là có tác động tích cực / tiêu cực đến xác suất thuộc về lớp dương. Các ràng buộc đơn điệu không được hỗ trợ cho bối cảnh đa lớp.

Ghi chú

Vì các danh mục là số lượng không có thứ tự, nên không thể thực thi các ràng buộc đơn điệu đối với các tính năng phân loại.

1.11.5.6. Song song cấp thấpLow-level parallelism¶

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 có các triển khai sử dụng OpenMP để song song hóa thông qua Cython. Để biết thêm chi tiết về cách kiểm soát số lượng chủ đề, vui lòng tham khảo ghi chú song song của chúng tôi.Parallelism notes.

Các phần sau được song song:

  • Tuy nhiên, các mẫu ánh xạ từ các giá trị thực đến các thùng có giá trị số nguyên [tìm thấy các ngưỡng bin tuy nhiên là tuần tự]

  • Biểu đồ xây dựng song song với các tính năng

  • Tìm điểm phân chia tốt nhất tại một nút được song song với các tính năng

  • Trong quá trình phù hợp, ánh xạ các mẫu vào trẻ em bên trái và bên phải được song song qua các mẫu

  • Các tính toán gradient và Hessians được song song với các mẫu

  • Dự đoán được song song qua các mẫu

1.11.5.7. Tại sao nó nhanh hơnWhy it’s faster¶

Nút thắt của một thủ tục tăng gradient đang xây dựng các cây quyết định. Xây dựng một cây quyết định truyền thống [như trong các GBDT khác

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5] yêu cầu sắp xếp các mẫu ở mỗi nút [cho mỗi tính năng]. Sắp xếp là cần thiết để mức tăng tiềm năng của một điểm phân chia có thể được tính toán hiệu quả. Do đó, việc chia một nút duy nhất có độ phức tạp của \ [\ mathcal {o} [n_ \ text {tính năng} \ lần n \ log [n]] \] trong đó \ [n \] là số lượng mẫu ở nút.\[\mathcal{O}[n_\text{features} \times n \log[n]]\] where \[n\] is the number of samples at the node.

Ngược lại,

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 không yêu cầu sắp xếp các giá trị tính năng và thay vào đó sử dụng cấu trúc dữ liệu được gọi là biểu đồ, trong đó các mẫu được đặt hàng ngầm. Xây dựng biểu đồ có độ phức tạp \ [\ mathcal {o} [n] \] hơn cái trước. Ngoài ra, thay vì xem xét các điểm phân chia \ [n \], chúng tôi ở đây chỉ xem xét các điểm phân chia
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
74, nhỏ hơn nhiều.\[\mathcal{O}[n]\] complexity, so the node splitting procedure has a \[\mathcal{O}[n_\text{features} \times n]\] complexity, much smaller than the previous one. In addition, instead of considering \[n\] split points, we here consider only
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
74 split points, which is much smaller.

Để xây dựng biểu đồ, dữ liệu đầu vào

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
63 cần được chia thành các thùng có giá trị nguyên. Quy trình Binning này yêu cầu sắp xếp các giá trị tính năng, nhưng nó chỉ xảy ra một lần khi bắt đầu quá trình tăng cường [không phải ở mỗi nút, như trong
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
4 và
>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> from sklearn.datasets import make_hastie_10_2

>>> X, y = make_hastie_10_2[random_state=0]
>>> X_train, X_test = X[:2000], X[2000:]
>>> y_train, y_test = y[:2000], y[2000:]

>>> clf = HistGradientBoostingClassifier[max_iter=100].fit[X_train, y_train]
>>> clf.score[X_test, y_test]
0.8965
5].

Cuối cùng, nhiều phần của việc thực hiện

>>> from sklearn.ensemble import HistGradientBoostingClassifier
>>> import numpy as np

>>> X = np.array[[0, 1, 2, np.nan]].reshape[-1, 1]
>>> y = [0, 0, 1, 1]

>>> gbdt = HistGradientBoostingClassifier[min_samples_leaf=1].fit[X, y]
>>> gbdt.predict[X]
array[[0, 0, 1, 1]]
5 và
>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
60 được song song hóa.

1.11.6. Phân loại bỏ phiếuVoting Classifier¶

Ý tưởng đằng sau

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 là kết hợp các phân loại máy học khác nhau về mặt khái niệm và sử dụng đa số phiếu bầu hoặc xác suất dự đoán trung bình [bỏ phiếu mềm] để dự đoán nhãn lớp. Một trình phân loại như vậy có thể hữu ích cho một tập hợp các mô hình hoạt động tốt như nhau để cân bằng các điểm yếu cá nhân của họ.

1.11.6.1. Nhãn lớp đa số [đa số/bỏ phiếu cứng] ¶Majority Class Labels [Majority/Hard Voting]¶

Trong đa số bỏ phiếu, nhãn lớp dự đoán cho một mẫu cụ thể là nhãn lớp đại diện cho phần lớn [chế độ] của nhãn lớp được dự đoán bởi mỗi phân loại riêng lẻ.

Ví dụ: nếu dự đoán cho một mẫu nhất định là

  • Phân loại 1 -> Lớp 1

  • Phân loại 2 -> Lớp 1

  • Phân loại 3 -> Lớp 2

Trình bỏ phiếu [với

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
09] sẽ phân loại mẫu là lớp 1 lớp 1 dựa trên nhãn lớp đa số.

Trong các trường hợp cà vạt,

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 sẽ chọn lớp dựa trên thứ tự sắp xếp tăng dần. Ví dụ: trong kịch bản sau

  • Phân loại 1 -> Lớp 2

  • Phân loại 2 -> Lớp 1

Nhãn lớp 1 sẽ được gán cho mẫu.

1.11.6.2. Cách sử dụng¶Usage¶

Ví dụ sau đây cho thấy cách phù hợp với phân loại quy tắc đa số:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
5

1.11.6.3. Xác suất trung bình có trọng số [bỏ phiếu mềm] ¶Weighted Average Probabilities [Soft Voting]¶

Trái ngược với bỏ phiếu đa số [bỏ phiếu cứng], bỏ phiếu mềm trả lại nhãn lớp là argmax của tổng số xác suất dự đoán.

Các trọng số cụ thể có thể được gán cho từng phân loại thông qua tham số

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
11. Khi các trọng số được cung cấp, xác suất lớp dự đoán cho mỗi phân loại được thu thập, nhân với trọng lượng phân loại và tính trung bình. Nhãn lớp cuối cùng sau đó được lấy từ nhãn lớp với xác suất trung bình cao nhất.

Để minh họa điều này bằng một ví dụ đơn giản, hãy để giả sử chúng tôi có 3 phân loại và các vấn đề phân loại 3 lớp trong đó chúng tôi gán các trọng số bằng nhau cho tất cả các phân loại: W1 = 1, W2 = 1, W3 = 1.

Các xác suất trung bình có trọng số cho một mẫu sau đó sẽ được tính toán như sau:

phân loại

lớp 1

lớp 2

Lớp 3

Phân loại 1

W1 * 0,2

W1 * 0,5

W1 * 0,3

Phân loại 2

W2 * 0,6

W2 * 0,3

W2 * 0.1

Phân loại 3

W3 * 0,3

W3 * 0,4

W3 * 0,3

W3 * 0,4

0.37

0.4

0.23

bình quân gia quyền

Ở đây, nhãn lớp dự đoán là 2, vì nó có xác suất trung bình cao nhất.

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
6

Ví dụ sau đây minh họa cách các vùng quyết định có thể thay đổi khi sử dụng
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 mềm dựa trên máy vectơ hỗ trợ tuyến tính, cây quyết định và bộ phân loại hàng xóm gần nhất:
Using the
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 with
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
14¶

1.11.6.4. Sử dụng

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 với ________ 214¶

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
7

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
08 cũng có thể được sử dụng cùng với
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
14 để điều chỉnh các hyperparamet của các công cụ ước tính riêng lẻ:
Usage¶

1.11.6.5. Cách sử dụng¶

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
8

Để dự đoán các nhãn lớp dựa trên các dự đoán của lớp dự đoán [các công cụ ước tính Scikit-learn trong Trình bỏ phiếu classifier phải hỗ trợ phương thức

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
17]:

>>> from sklearn.ensemble import RandomForestClassifier
>>> X = [[0, 0], [1, 1]]
>>> Y = [0, 1]
>>> clf = RandomForestClassifier[n_estimators=10]
>>> clf = clf.fit[X, Y]
9

Tùy chọn, trọng số có thể được cung cấp cho các phân loại riêng lẻ:Voting Regressor¶

1.11.7. Bỏ phiếu Thỉnh hủy

Ý tưởng đằng sau
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
18 là kết hợp các hồi quy học máy khác nhau về mặt khái niệm và trả về các giá trị dự đoán trung bình. Một bộ hồi quy như vậy có thể hữu ích cho một tập hợp các mô hình hoạt động tốt như nhau để cân bằng các điểm yếu cá nhân của họ.
Usage¶

1.11.7.1. Cách sử dụng¶

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
0

Ví dụ sau đây cho thấy cách phù hợp với người bỏ phiếu:Stacked generalization¶

1.11.8. Chung xếp chồng lên nhau[W1992] [HTF]. More precisely, the predictions of each individual estimator are stacked together and used as input to a final estimator to compute the prediction. This final estimator is trained through cross-validation.

Tổng quát hóa xếp chồng là một phương pháp kết hợp các công cụ ước tính để giảm sự thiên vị của chúng [W1992] [HTF]. Chính xác hơn, dự đoán của từng công cụ ước tính riêng lẻ được xếp chồng lên nhau và được sử dụng làm đầu vào cho một công cụ ước tính cuối cùng để tính toán dự đoán. Công cụ ước tính cuối cùng này được đào tạo thông qua xác thực chéo.

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
19 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
20 cung cấp các chiến lược như vậy có thể được áp dụng cho các vấn đề phân loại và hồi quy.

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
1

Tham số

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 tương ứng với danh sách các công cụ ước tính được xếp chồng lên nhau song song trên dữ liệu đầu vào. Nó nên được đưa ra như một danh sách các tên và công cụ ước tính:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
2

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
22 sẽ sử dụng các dự đoán của
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 làm đầu vào. Nó cần phải là một trình phân loại hoặc một bộ hồi quy khi sử dụng
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
19 hoặc
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
20, tương ứng:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
3

Để đào tạo

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
22, phương pháp
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
28 cần được gọi trên dữ liệu đào tạo:

Trong quá trình đào tạo,

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 được trang bị trên toàn bộ dữ liệu đào tạo
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
30. Chúng sẽ được sử dụng khi gọi
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
31 hoặc
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
17. Để khái quát hóa và tránh quá mức,
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
22 được đào tạo về các mẫu ngoài bằng cách sử dụng
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
34 trong nội bộ.

Đối với

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
19, lưu ý rằng đầu ra của
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 được điều khiển bởi tham số
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
37 và nó được gọi bởi mỗi công cụ ước tính. Tham số này là một chuỗi, tên phương thức ước tính hoặc
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
38 sẽ tự động xác định một phương thức khả dụng tùy thuộc vào tính khả dụng, được kiểm tra theo thứ tự ưu tiên:
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
17,
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
40 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
31.

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
4

A

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
20 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
19 có thể được sử dụng như bất kỳ trình phân loại hoặc phân loại nào khác, phơi bày các phương thức
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
31,
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
17 và
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
40, ví dụ:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
5

Lưu ý rằng cũng có thể nhận được đầu ra của

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
21 xếp chồng lên nhau bằng phương pháp
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
48:

Trong thực tế, một yếu tố dự đoán xếp chồng dự đoán tốt như yếu tố dự đoán tốt nhất của lớp cơ sở và thậm chí đôi khi vượt trội so với nó bằng cách kết hợp các điểm mạnh khác nhau của các dự đoán này. Tuy nhiên, đào tạo một yếu tố dự đoán xếp chồng là tính toán đắt tiền.

Ghi chú

Ghi chú

Có thể đạt được nhiều lớp xếp chồng bằng cách gán

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
22 cho
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
19 hoặc
>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
20:

>>> from sklearn.model_selection import cross_val_score
>>> from sklearn.datasets import make_blobs
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.ensemble import ExtraTreesClassifier
>>> from sklearn.tree import DecisionTreeClassifier

>>> X, y = make_blobs[n_samples=10000, n_features=10, centers=100,
...     random_state=0]

>>> clf = DecisionTreeClassifier[max_depth=None, min_samples_split=2,
...     random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.98...

>>> clf = RandomForestClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[]
0.999...

>>> clf = ExtraTreesClassifier[n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0]
>>> scores = cross_val_score[clf, X, y, cv=5]
>>> scores.mean[] > 0.999
True
6

Bài Viết Liên Quan

Chủ Đề