sklearn.tree.ExtraTreeRegressor?
class sklearn.tree.ExtraTreeRegressor(*, criterion='mse', splitter='random', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', random_state=None, min_impurity_decrease=0.0, min_impurity_split=None, max_leaf_nodes=None, ccp_alpha=0.0)
極端隨機回歸樹
極端隨機樹與傳統的決策樹在構建方式上有所不同。當尋找將節點的樣本分成兩組的最佳分割時,將對隨機選擇的max_features中的每個特征進行隨機分割,并選擇其中的最佳分割。當 max_features
設置為1時,這等于建立一個完全隨機的決策樹。
注意:極端隨機數只能在集成方法中使用
在用戶指南中閱讀更多內容
參數 | 說明 |
---|---|
criterion | {“mse”, “friedman_mse”, “mae”}, default=”mse” 該函數用來測量分割的質量 - mse:表示均方誤差 - friedman_mse: 均方誤差等于方差減少作為特征選擇準則 - mae: 表示絕對誤差 新版本0.18:平均絕對誤差(MAE)標準 |
splitter | {“random”, “best”}, default=”random” 用于在每個節點選擇分割的策略 - best:最佳分割 - random:最佳隨機分割 默認是random |
max_depth | int, default=None 樹的最大深度 如果為None,則將節點展開,直到所有葉子都是純凈的,或者直到所有葉子都包含少于min_samples_split個樣本 默認為None |
min_samples_split | int or float, default=2 分割一個內部節點所需的最小樣本數 - int:如果是int,則考慮min_samples_split作為最小值 - float:如果是float,那么min_samples_split是一個分數,而ceil(min_samples_split * n_samples)是每個分割的最小樣本數。 默認值為:2 在0.18版本中更改:增加了分數的浮點值。 |
min_samples_leaf | int or float, default=1 一個葉節點上所需的最小樣本數。只有當它在每個左右分支中都留下至少min_samples_leaf訓練樣本時,任何深度的分割點才會被考慮。這可能會產生平滑模型的效果,特別是在回歸中。 int:如果是int,則考慮min_samples_leaf作為最小值 float:如果是float,那么min_samples_leaf是一個分數,而ceil(min_samples_leaf * n_samples)是每個節點的最小樣本數 在0.18版本中更改:增加了分數的浮點值 |
min_weight_fraction_leaf | float, default=0.0 在所有葉節點處(所有輸入樣本)的權重總和中的最小加權分數。如果未提供sample_weight,則樣本的權重相等。 |
max_features | int, float, {“auto”, “sqrt”, “log2”} or None, default=”auto” 尋找最佳分割時要考慮的特性數量 - int:如果是int,則考慮每個分割處的max_features特性 - float:如果是float,那么max_features是一個分數,并且int(max_features * n_features) features會在每次分割時被考慮 - auto:如果是auto,則max_features=n_features - sqrt:如果是“sqrt”,則max_features=sqrt(n_features) - log2:如果“log2”,則max_features=log2(n_features) - None:如果None, then max_features=n_features 默認是auto 注意:在找到節點樣本的至少一個有效分區之前,對分割的搜索不會停止,即使它需要有效地檢查超過max_features的特性。 |
random_state | int, RandomState instance, default=None 用于隨機選擇每次分割時使用的max_features。有關詳細信息,請參見詞匯表 |
min_impurity_decrease | float, default=0.0 如果節點分裂會導致雜質的減少大于或等于該值,則該節點將被分裂 加權雜質減少方程如下: N_t / N * ( impurity - N_t_R / N_t * right_impurity - N_t_L / N_t * left_impurity ) 其中N為樣本總數,N_t為當前節點的樣本數,N_t_L為左子節點的樣本數,N_t_R為右子節點的樣本數。 如果sample_weight被傳遞,N、N_t、N_t_R和N_t_L都指向加權和。 新版本為0.19 |
min_impurity_split | float, (default=0) 最小雜質分裂,如果節點的雜質高于閾值,則該節點將分裂,否則為葉。 注意:從版本0.19開始被棄用: min_impurity_split在0.19中被棄用,轉而支持min_impurity_decrease。min_impurity_split的默認值在0.23中從1e-7更改為0,在0.25中將被刪除。使用min_impurity_decrease代替。 |
max_leaf_nodes | int, default=None 以最佳優先的方式生成具有max_leaf_nodes的樹。最佳節點定義為雜質的相對減少。如果為None,則葉節點數不受限制。 |
ccp_alpha | non-negative float, default=0.0 復雜度參數用于最小代價復雜度剪枝。具有最大成本復雜度的子樹小于 ccp_alpha 所選擇的子樹。默認情況下,不執行修剪。有關詳細信息,請參見最小化成本-復雜性修剪。 |
屬性 | 說明 |
---|---|
max_features_ | int max_features的推斷值 |
n_features_ | int 執行fit時的特征數 |
feature_importances_ | ndarray of shape (n_features,) 返回特性的重要性 |
n_outputs_ | intfit 執行時的輸出數量 |
tree_ | Tree 基礎的Tree對象。 help(sklearn.tree._tree.Tree) 有關樹對象的屬性, 請參閱, 有關這些屬性的基本用法,請參閱 決策樹的結構。 |
另見
sklearn.ensemble.ExtraTreesClassifier
sklearn.ensemble.ExtraTreesRegressor
注釋
控制樹(例如max_depth
,min_samples_leaf
等)大小的參數的默認值會導致樹的完全生長和未修剪,這在某些數據集上可能非常大。為了減少內存消耗,應通過設置這些參數值來控制樹的復雜性和大小。
參考文獻:
P. Geurts, D. Ernst., and L. Wehenkel, “Extremely randomized trees”, Machine Learning, 63(1), 3-42, 2006.(D.恩斯特。和L. Wehenkel,“極隨機化樹”,機器學習,63(1),3- 42,2006。)
例子:
>>> from sklearn.datasets import load_diabetes
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.ensemble import BaggingRegressor
>>> from sklearn.tree import ExtraTreeRegressor
>>> X, y = load_diabetes(return_X_y=True)
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, random_state=0)
>>> extra_tree = ExtraTreeRegressor(random_state=0)
>>> reg = BaggingRegressor(extra_tree, random_state=0).fit(
... X_train, y_train)
>>> reg.score(X_test, y_test)
0.33...
方法:
方法 | 說明 |
---|---|
apply (X[, check_input]) |
返回每個樣本預測為的葉的索引 |
cost_complexity_pruning_path (X, y[, …]) |
在最小代價復雜度剪枝過程中計算剪枝路徑 |
decision_path (X[, check_input]) |
返回樹中的決策路徑 |
fit (X, y[, sample_weight, check_input, …]) |
從訓練集(X, y)構建決策樹回歸器 |
get_depth () |
返回決策樹的深度 |
get_n_leaves () |
返回決策樹的葉節點數 |
get_params ([deep]) |
獲取這個估計器的參數 |
predict (X[, check_input]) |
預測X的類或回歸值 |
score (X, y[, sample_weight]) |
返回預測的決定系數R^2 |
set_params (**params) |
設置這個估計器的參數 |
__init__(*, criterion='mse', splitter='random', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', random_state=None, min_impurity_decrease=0.0, min_impurity_split=None, max_leaf_nodes=None, ccp_alpha=0.0)
初始化self。請參閱help(type(self))以獲得準確的說明
apply(X, check_input=True)
返回每個樣本預測為葉子的索引
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 樣本數據 |
check_input | bool, default=True 允許繞過幾個輸入檢查。除非您知道自己在做什么,否則不要使用此參數。 |
返回值 | 說明 |
---|---|
X_leaves | array-like of shape (n_samples,) 對于x中的每個數據點x,返回葉子x的索引。葉片編號在[0; self.tree_.node_count),可能在編號中帶有空值 |
cost_complexity_pruning_path(X, y, sample_weight=None)
在最小代價復雜度剪枝過程中計算剪枝路徑
有關修剪過程的詳細信息,請參見最小成本復雜性修剪。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 訓練樣本數據 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) 目標值(類標簽)為整數或字符串 |
sample_weight | array-like of shape (n_samples,), default=None 樣本權重。如果為None,則對樣本進行平均加權。在每個節點中搜索拆分時,將忽略創建凈凈值為零或負權重的子節點的拆分。如果拆分會導致任何單個類在任一子節點中都負負重,則也將忽略拆分。 |
返回值 | 說明 |
---|---|
ccp_path | Bunch 類字典的對象 |
ccp_alphas | ndarray 修剪過程中子樹的有效阿爾法值 |
impurities | ndarrayccp_alphas 中對應alpha值的子樹葉子的雜質之和。 |
decision_path(X, check_input=True)
返回樹中的決策路徑
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 樣本數據 |
check_input | bool, default=True 允許繞過幾個輸入檢查。除非您知道自己在做什么,否則不要使用此參數。 |
返回值 | 說明 |
---|---|
indicator | sparse matrix of shape (n_samples, n_nodes) 返回一個節點指示器CSR矩陣,其中非零元素表示樣本經過節點。 |
property feature_importances_
返回特征的重要性
特征的重要性計算為該特征帶來的標準的(標準化)總縮減。這也被稱為基尼重要性。
注意: 基于雜質的特征重要性可能會誤導高基數特征(許多唯一值)。另見 sklearn.inspection.permutation_importance
。
返回值 | 說明 |
---|---|
feature_importances_ | ndarray of shape (n_features,) 按功能對標準的總歸約化進行歸一化(基尼重要性) |
fit(X, y, sample_weight=None, check_input=True, X_idx_sorted=None)
從訓練集(X, y)構建決策樹回歸器
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 訓練樣本 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) 目標值(真實數字) |
sample_weight | array-like of shape (n_samples,), default=None 樣本的權重,如果為None,則對樣本進行平均加權。在每個節點中搜索拆分時,將忽略創建凈凈值為零或負權重的子節點的拆分。 |
check_input | bool, default=True 允許繞過幾個輸入檢查。除非您知道自己在做什么,否則不要使用此參數。 |
X_idx_sorted | array-like of shape (n_samples, n_features), default=None 如果在同一數據集上生長了許多樹,則可以在樹之間緩存順序。如果為None,則將在此處對數據進行排序。除非您知道要做什么,否則不要使用此參數。 |
返回值 | 說明 |
---|---|
self | DecisionTreeRegressor 擬合估計器 |
get_depth()
返回決策樹的深度
樹的深度是根和葉子之間的最大距離
返回值 | 說明 |
---|---|
self.tree_.max_depth | int 樹的最大深度 |
get_n_leaves()
返回決策樹的葉節點數
返回值 | 說明 |
---|---|
self.tree_.n_leaves | int 葉子的數量 |
get_params(deep=True)
獲取這個估計器的參數
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,將返回此估計器的參數以及包含的作為估計器的子對象。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到它們的值 |
predict(X, check_input=True)
預測X的類或回歸值
對于分類模型,返回X中每個樣本的預測類。對于回歸模型,返回基于X的預測值。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix} of shape (n_samples, n_features) 樣本數據 |
check_input | bool, default=True 允許繞過幾個輸入檢查。除非您知道自己在做什么,否則不要使用此參數 |
返回值 | 說明 |
---|---|
y | array-like of shape (n_samples,) or (n_samples, n_outputs) 預測的類,或預測的值 |
score(X, y, sample_weight=None)
返回預測的決定系數R^2
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) X的真實值 |
sample_weight | array-like of shape (n_samples,), default=None 樣本權重 |
返回值 | 說明 |
---|---|
score | float R^2 of self.predict(X) wrt. y. |
注釋:
調用score
回歸器時使用的R2得分multioutput='uniform_average'
從0.23版本開始使用 ,以與默認值保持一致r2_score
。這會影響score
所有多輸出回歸變量的方法(MultiOutputRegressor
除外)
set_params(**params)
設置此估算器的參數
該方法適用于簡單的估計器以及嵌套對象(例如管道)
參數 | 說明 |
---|---|
**params | dict 估算器參數 |
返回值 | 說明 |
---|---|
self | object 估算器實例 |