# Python sklearn.ensemble.RandomTreesEmbedding用法及代码示例

### 用法:

``class sklearn.ensemble.RandomTreesEmbedding(n_estimators=100, *, max_depth=5, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_leaf_nodes=None, min_impurity_decrease=0.0, sparse_output=True, n_jobs=None, random_state=None, verbose=0, warm_start=False)``

### 参数：

n_estimatorsint 默认=100

max_depthint 默认=5

min_samples_splitint 或浮点数，默认=2

• 如果int 则将`min_samples_split` 视为最小数量。
• 如果是浮点数，那么 `min_samples_split` 是一个分数，而 `ceil(min_samples_split * n_samples)` 是每个拆分的最小样本数。
min_samples_leafint 或浮点数，默认=1

• 如果int 则将`min_samples_leaf` 视为最小数量。
• 如果是浮点数，那么 `min_samples_leaf` 是一个分数，而 `ceil(min_samples_leaf * n_samples)` 是每个节点的最小样本数。
min_weight_fraction_leaf浮点数，默认=0.0

max_leaf_nodesint 默认=无

min_impurity_decrease浮点数，默认=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_R``N_t_L` 都是指加权和，如果通过了 `sample_weight`

sparse_output布尔，默认=真

n_jobsint 默认=无

random_stateint RandomState 实例或无，默认=无

verboseint 默认=0

warm_start布尔，默认=假

### 属性：

base_estimator_

estimators_

`feature_importances_`ndarray 形状 (n_features,)

`n_features_`int

n_features_in_int

feature_names_in_ndarray 形状(`n_features_in_`，)

n_outputs_int

one_hot_encoder_OneHotEncoder 实例

One-hot 编码器用于创建稀疏嵌入。

### 参考：

1

P. Geurts、D. Ernst. 和 L. Wehenkel，“Extremely randomized trees”，机器学习，63(1)，3-42，2006。

2

Moosmann, F. 和 Triggs, B. 和 Jurie, F. “使用随机聚类森林的快速判别视觉码本” NIPS 2007

### 例子：

``````>>> from sklearn.ensemble import RandomTreesEmbedding
>>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]
>>> random_trees = RandomTreesEmbedding(
...    n_estimators=5, random_state=0, max_depth=1).fit(X)
>>> X_sparse_embedding = random_trees.transform(X)
>>> X_sparse_embedding.toarray()
array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],
[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],
[0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],
[1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],
[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])``````
{"ft_lang_label":"__label__zh","ft_lang_prob":0.5144696,"math_prob":0.99845356,"size":4246,"snap":"2023-14-2023-23","text_gpt3_token_len":2128,"char_repetition_ratio":0.21593589,"word_repetition_ratio":0.08988764,"special_character_ratio":0.2552991,"punctuation_ratio":0.29832572,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9814283,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-07T02:29:55Z\",\"WARC-Record-ID\":\"<urn:uuid:2e7594fd-6f4d-4a76-874b-ec3320ba9cc0>\",\"Content-Length\":\"22734\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a23354a8-e0df-4f69-8a10-2d269093b5ae>\",\"WARC-Concurrent-To\":\"<urn:uuid:8c625518-8011-4dbf-8c19-2e981531cdce>\",\"WARC-IP-Address\":\"47.93.116.66\",\"WARC-Target-URI\":\"https://vimsky.com/examples/usage/python-sklearn.ensemble.RandomTreesEmbedding-sk.html\",\"WARC-Payload-Digest\":\"sha1:SPOF3ZMRXOURR4QKE5ES3RXSMJV6BQ4P\",\"WARC-Block-Digest\":\"sha1:HJQHGRT34YW34QD6D7X6NTJF62CP5BNU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224653501.53_warc_CC-MAIN-20230607010703-20230607040703-00474.warc.gz\"}"}