更新时间:2022-01-27 GMT+08:00
分享

随机森林分类特征重要性

概述

采用随机森林分类算法计算数据集特征的特征重要性

输入

参数

子参数

参数说明

inputs

dataframe

参数必选,表示输入的数据集;如果没有pipeline_model和random_forest_classify_model参数,表示直接根据数据集训练随机森林分类模型得到特征重要性

pipeline_model

参数可选,如果含有该参数,表示根据上游的pyspark pipeline模型对象pipeline_model来计算特征重要性

random_forest_classify_model

参数可选,如果含有该参数,表示根据上游的random_forest_classify_model对象来计算特征重要性

输出

特征重要性结果数据集

参数说明

参数

子参数

参数说明

input_columns_str

-

数据集的特征列名组成的格式化字符串,例如:

"column_a"

"column_a,column_b"

label_col

-

目标列名

model_input_features_col

-

特征向量的列名

classifier_label_index_col

-

将目标列按照标签编码后的列名,默认为"label_index"

prediction_index_col

-

训练模型时,预测结果对应标签的列名,默认为"prediction_index"

prediction_col

-

训练模型时,预测结果对应的列名,默认为"prediction"

max_depth

-

树的最大深度,默认为5

max_bins

-

特征分裂时的最大分箱个数,默认为32

min_instances_per_node

-

树分裂时要求每个节点必须包含的实例数目,默认为1

min_info_gain

-

最小信息增益,默认为0.0

impurity

-

纯度,支持"gini"和"entropy",默认为"gini"

num_trees

-

树的个数,默认为20

feature_subset_strategy

-

每个树节点分裂时使用的特征个数,默认为"all"

subsampling_rate

-

训练每棵树时,对训练集的抽样率,默认为1.0

seed

-

随机数种子,默认为0

样例

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

分享:

    相关文档

    相关产品

close