更新时间:2023-05-05 GMT+08:00
分享

朴素贝叶斯分类

概述

“朴素贝叶斯”节点用于产生多分类模型,用户在使用时需要指定数据的“Role”字段,默认支持“Input”、“Target”、“Rejected”、“ID”四种类型,且只能选择其一种。

朴素贝叶斯算法是基于贝叶斯定理与特征条件独立假设的分类方法。

朴素贝叶斯法实现简单,学习与预测的效率都很高,是一种常用的方法。对于给定的训练数据集:

  1. 首先基于特征条件独立假设学习输入/输出的联合概率分布。
  2. 然后基于此模型,对给定的输入x,利用贝叶斯定理求出后验概率最大的输出y。

输入

参数

子参数

参数说明

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

-

目标列经过标签编码后的新的列名,默认为"label_index"

classifier_feature_vector_col

-

算子输入的特征向量列的列名,默认为"model_features"

prediction_col

-

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

prediction_index_col

-

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

smoothing

-

平滑参数,默认为1.0

model_type

-

模型类型,支持multinomial、bernoulli,默认为"multinomial"

样例

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": ""}
    "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_col": "prediction",  # @param {"label": "prediction_col", "type": "string", "required": "true", "helpTip": ""}
    "prediction_index_col": "prediction_index",  # @param {"label": "prediction_index_col", "type": "string", "required": "true", "helpTip": ""}
    "smoothing": 1.0,  # @param {"label": "smoothing", "type": "number", "required": "true", "range": "[0,none)", "helpTip": ""}
    "model_type": "multinomial"  # @param {"label": "model_type", "type": "enum", "required": "true", "options": "multinomial,bernoulli", "helpTip": ""}
}
naive_bayes_classifier____id___ = MLSNaiveBayesClassifier(**params)
naive_bayes_classifier____id___.run()
# @output {"label":"pipeline_model","name":"naive_bayes_classifier____id___.get_outputs()['output_port_1']","type":"PipelineModel"}

分享:

    相关文档

    相关产品