华为云AI开发平台ModelArts随机森林分类_云淘科技

概述

“随机决策森林分类”节点用于产生二分类或多分类模型。随机决策森林是用随机的方式建立一个森林模型,森林由很多的决策树组成,每棵决策树之间没有关联。当有一个新的样本输入时,森林中的每一棵决策树分别进行判断,哪一类被选择最多,就预测这个样本属于那一类。

随机决策森林分类中的决策树算法通过基尼不纯度(Gini impurity)或熵(Entropy)来对一个集合的有序程度进行量化,并对一次拆分进行量化评价。

基尼不纯度是指将来自集合中的某种结果随机应用于集合中某一数据项的预期误差率,计算公式如下:

熵是信息论中的概念,用来表示集合的无序程度,熵越大表示集合越混乱,反之则表示集合越有序,计算公式如下:

fi表示类别i样本数量占所有样本的比例,C表示数据类别数。

输入

参数

子参数

参数说明

inputs

dataframe

inputs为字典类型,dataframe为pyspark中的DataFrame类型对象

输出

spark pipeline类型的模型

参数说明

参数

子参数

参数说明

b_use_default_encoder

是否使用默认编码,默认为True

input_features_str

输入的列名以逗号分隔组成的字符串,例如:

“column_a”

“column_a,column_b”

label_col

目标列

classifier_label_index_col

传给分类器的目标列,必须为数值列

classifier_feature_vector_col

传给分类器的特征列,必须为向量列

prediction_col

算子输出的预测label的列名,默认为”prediction”

prediction_index_col

算子输出的预测label对应的标签列,默认为”prediction_index”

max_depth

树的最大深度,默认为5

max_bins

最大分箱数,默认为32

min_instances_per_node

节点分割时,要求子节点必须包含的最少实例数,默认为1

min_info_gain

节点是否分割要求的最小信息增益,默认为0

impurity

计算信息增益的方法,支持entropy、gini,默认为”gini”

num_trees

树的个数,默认为20

feature_subset_strategy

节点分割时考虑用到的特征列的策略,支持auto、all、onethird、sqrt、log2、n,默认为”all”

subsampling_rate

学习每棵决策树用到的训练集的比例,默认为1.0

seed

随机数种子,默认为0

样例

inputs = {
    "dataframe": None  # @input {"label":"dataframe","type":"DataFrame"}
}
params = {
    "inputs": inputs,
    "b_output_action": True,
    "b_use_default_encoder": True,  # @param {"label": "b_use_default_encoder", "type": "boolean", "required": "true", "helpTip": ""}
    "input_features_str": "",  # @param {"label": "input_features_str", "type": "string", "required": "false", "helpTip": ""}
    "outer_pipeline_stages": None,
    "label_col": "",  # @param {"label": "label_col", "type": "string", "required": "true", "helpTip": "target label column"}
    "classifier_label_index_col": "label_index",  # @param {"label": "classifier_label_index_col", "type": "string", "required": "true", "helpTip": ""}
    "classifier_feature_vector_col": "model_features",  # @param {"label": "classifier_feature_vector_col", "type": "string", "required": "true", "helpTip": ""}
    "prediction_index_col": "prediction_index",  # @param {"label": "prediction_index_col", "type": "string", "required": "true", "helpTip": ""}
    "prediction_col": "prediction",  # @param {"label": "prediction_col", "type": "string", "required": "true", "helpTip": ""}
    "max_depth": 5,  # @param {"label": "max_depth", "type": "integer", "required": "true", "range": "(0,2147483647]", "helpTip": ""}
    "max_bins": 32,  # @param {"label": "max_bins", "type": "integer", "required": "true", "range": "(0,2147483647]", "helpTip": ""}
    "min_instances_per_node": 1,  # @param {"label": "min_instances_per_node", "type": "integer", "required": "true", "range": "(0,2147483647]", "helpTip": ""}
    "min_info_gain": 0.0,  # @param {"label": "min_info_gain", "type": "number", "required": "true", "range": "[0,none)", "helpTip": ""}
    "impurity": "gini",  # @param {"label": "impurity", "type": "enum", "required": "true", "options": "entropy,gini", "helpTip": ""}
    "num_trees": 20,  # @param {"label": "num_trees", "type": "integer", "required": "true", "range": "(0,2147483647]", "helpTip": ""}
    "feature_subset_strategy": "all",  # @param {"label": "feature_subset_strategy", "type": "enum", "required": "true", "options":"auto,all,onethird,sqrt,log2", "helpTip": ""}
    "subsampling_rate": 1.0,  # @param {"label": "subsampling_rate", "type": "number", "required": "true", "range": "(0,1.0]", "helpTip": ""}
    "seed": 0  # @param {"label": "seed", "type": "integer", "required": "true", "range":"[0,2147483647]","helpTip": "seed"}
}
rf_classifier____id___ = MLSRandomForestClassifier(**params)
rf_classifier____id___.run()
# @output {"label":"pipeline_model","name":"rf_classifier____id___.get_outputs()['output_port_1']","type":"PipelineModel"}

父主题: 分类

同意关联代理商云淘科技,购买华为云产品更优惠(QQ 78315851)

内容没看懂? 不太想学习?想快速解决? 有偿解决: 联系专家