# 应用专题 / 数学算法 ## `decisionTreeClassifier` 声明:class 使用决策树进行分类并支持类别概率、决策路径和成本复杂度剪枝 ### `Criterion` 声明:field 切分质量衡量标准,支持 `gini`、`entropy` 和 `log_loss`,默认 `gini` 可见性:`public` 类型:string ### `Splitter` 声明:field 节点拆分策略,可选 `best` 或 `random`,默认 `best` 可见性:`public` 类型:string ### `Max_depth` 声明:field 树的最大深度;为空时继续展开直到叶节点纯净或样本数不足 可见性:`public` 类型:integer ### `Random_state` 声明:field 控制估计器随机性以便复现结果 可见性:`public` 类型:integer ### `Class_weight` 声明:field 与类别关联的权重;为空时各类别权重均为 1 可见性:`public` 类型:array ### `Ccp_alpha` 声明:field 最小成本复杂性剪枝参数,默认 0.0 可见性:`public` 类型:real ### `Classes_` 声明:field 训练后得到的类标签,或多输出模型的类标签数组列表 可见性:`public` 类型:array ### `Feature_importances_` 声明:field 训练后得到的特征重要程度 可见性:`public` 类型:array ### `create(criterion, splitter, max_depth, min_samples_split, min_samples_leaf, min_weight_fraction_leaf, max_features, random_state, max_leaf_nodes, min_impurity_decrease, class_weight, ccp_alpha)` 声明:function 初始化决策树分类器 可见性:`public` | 参数 | 类型 | 说明 | | -------------------------- | ------------- | ---------------------------------- | | `criterion` | string | 切分质量衡量标准 | | `splitter` | string | 节点拆分策略 | | `max_depth` | integer | 树的最大深度 | | `min_samples_split` | integer\|real | 拆分内部节点所需的最小样本数或比例 | | `min_samples_leaf` | integer\|real | 叶节点所需的最小样本数或比例 | | `min_weight_fraction_leaf` | real | 叶节点的最小加权比例 | | `max_features` | any | 寻找最佳分割时考虑的特征数量 | | `random_state` | integer | 随机状态 | | `max_leaf_nodes` | integer | 最大叶节点数 | | `min_impurity_decrease` | real | 允许切分的最小不纯度下降值 | | `class_weight` | array | 类别权重 | | `ccp_alpha` | real | 最小成本复杂性剪枝参数 | ### `Fit(X, y, sample_weight, check_input)` 声明:function 根据训练集建立决策树分类器 可见性:`public` | 参数 | 类型 | 说明 | | --------------- | ------- | ----------------------------- | | `X` | array | 二维训练特征数组 | | `y` | array | 类标签或多输出目标数组 | | `sample_weight` | array | 各样本权重;默认值为 `nil` | | `check_input` | boolean | 是否执行输入检查,默认 `True` | ### `Get_depth()` 声明:function 返回决策树深度 可见性:`public` 返回:integer ### `Get_n_leaves()` 声明:function 返回决策树叶节点数 可见性:`public` 返回:integer ### `Predict_proba(X, check_input)` 声明:function 预测输入样本的类别概率 可见性:`public` | 参数 | 类型 | 说明 | | ------------- | ------- | ----------------------------- | | `X` | array | 需要预测的二维特征数组 | | `check_input` | boolean | 是否执行输入检查,默认 `True` | 返回:array ### `Predict_log_proba(X)` 声明:function 预测输入样本的类别对数概率 可见性:`public` | 参数 | 类型 | 说明 | | ---- | ----- | ---------------------- | | `X` | array | 需要预测的二维特征数组 | 返回:array ### `Predict(X, check_input)` 声明:function 预测输入样本的类别标签 可见性:`public` | 参数 | 类型 | 说明 | | ------------- | ------- | ----------------------------- | | `X` | array | 需要预测的二维特征数组 | | `check_input` | boolean | 是否执行输入检查,默认 `True` | 返回:array ### `Decision_path(X, check_input)` 声明:function 返回样本通过决策树节点的决策路径 可见性:`public` | 参数 | 类型 | 说明 | | ------------- | ------- | ----------------------------- | | `X` | array | 需要计算路径的二维特征数组 | | `check_input` | boolean | 是否执行输入检查,默认 `True` | 返回:array ### `Get_feature_importances_()` 声明:function 返回按特征归一化的特征重要程度 可见性:`public` 返回:array ### `Cost_complexity_pruning_path(X, y, sample_weight)` 声明:function 计算最小成本复杂性剪枝路径 可见性:`public` | 参数 | 类型 | 说明 | | --------------- | ----- | -------------------------- | | `X` | array | 二维训练特征数组 | | `y` | array | 类标签或多输出目标数组 | | `sample_weight` | array | 各样本权重;默认值为 `nil` | 返回:array ## `decisionTreeRegressor` 声明:class 使用决策树进行回归并支持决策路径和成本复杂度剪枝 ### `Criterion` 声明:field 切分质量衡量标准,默认 `squared_error` 可见性:`public` 类型:string ### `Splitter` 声明:field 节点拆分策略,可选 `best` 或 `random`,默认 `best` 可见性:`public` 类型:string ### `Max_depth` 声明:field 树的最大深度;为空时继续展开直到满足停止条件 可见性:`public` 类型:integer ### `Random_state` 声明:field 控制估计器随机性以便复现结果 可见性:`public` 类型:integer ### `Ccp_alpha` 声明:field 最小成本复杂性剪枝参数,默认 0.0 可见性:`public` 类型:real ### `Feature_importances_` 声明:field 训练后得到的特征重要程度 可见性:`public` 类型:array ### `create(criterion, splitter, max_depth, min_samples_split, min_samples_leaf, min_weight_fraction_leaf, max_features, random_state, max_leaf_nodes, min_impurity_decrease, ccp_alpha)` 声明:function 初始化决策树回归器 可见性:`public` | 参数 | 类型 | 说明 | | -------------------------- | ------------- | ---------------------------------- | | `criterion` | string | 切分质量衡量标准 | | `splitter` | string | 节点拆分策略 | | `max_depth` | integer | 树的最大深度 | | `min_samples_split` | integer\|real | 拆分内部节点所需的最小样本数或比例 | | `min_samples_leaf` | integer\|real | 叶节点所需的最小样本数或比例 | | `min_weight_fraction_leaf` | real | 叶节点的最小加权比例 | | `max_features` | any | 寻找最佳分割时考虑的特征数量 | | `random_state` | integer | 随机状态 | | `max_leaf_nodes` | integer | 最大叶节点数 | | `min_impurity_decrease` | real | 允许切分的最小不纯度下降值 | | `ccp_alpha` | real | 最小成本复杂性剪枝参数 | ### `Fit(X, y, sample_weight, check_input)` 声明:function 根据训练集建立决策树回归器 可见性:`public` | 参数 | 类型 | 说明 | | --------------- | ------- | ----------------------------- | | `X` | array | 二维训练特征数组 | | `y` | array | 回归目标或多输出目标数组 | | `sample_weight` | array | 各样本权重;默认值为 `nil` | | `check_input` | boolean | 是否执行输入检查,默认 `True` | ### `Get_depth()` 声明:function 返回决策树深度 可见性:`public` 返回:integer ### `Get_n_leaves()` 声明:function 返回决策树叶节点数 可见性:`public` 返回:integer ### `Predict(X, check_input)` 声明:function 预测输入样本的回归值 可见性:`public` | 参数 | 类型 | 说明 | | ------------- | ------- | ----------------------------- | | `X` | array | 需要预测的二维特征数组 | | `check_input` | boolean | 是否执行输入检查,默认 `True` | 返回:array ### `Decision_path(X, check_input)` 声明:function 返回样本通过决策树节点的决策路径 可见性:`public` | 参数 | 类型 | 说明 | | ------------- | ------- | ----------------------------- | | `X` | array | 需要计算路径的二维特征数组 | | `check_input` | boolean | 是否执行输入检查,默认 `True` | 返回:array ### `Get_feature_importances_()` 声明:function 返回按特征归一化的特征重要程度 可见性:`public` 返回:array ### `Cost_complexity_pruning_path(X, y, sample_weight)` 声明:function 计算最小成本复杂性剪枝路径 可见性:`public` | 参数 | 类型 | 说明 | | --------------- | ----- | -------------------------- | | `X` | array | 二维训练特征数组 | | `y` | array | 回归目标或多输出目标数组 | | `sample_weight` | array | 各样本权重;默认值为 `nil` | 返回:array ## `cond_entropy_cc(c_x, c_y, k, base)` 声明:function 获取连续变量与连续变量的条件熵 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `c_x` | array | 一维数字数组,一维连续数据 | | `c_y` | array | 一维数字数组,一维连续数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `cond_entropy_cd(c_x, d_y, k, base)` 声明:function 获取连续变量与离散变量的条件熵 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `c_x` | array | 一维数字数组,一维连续数据 | | `d_y` | array | 一维数字数组,一维离散数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `cond_entropy_dc(d_x, c_y, k, base)` 声明:function 获取离散变量与连续变量的条件熵 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `d_x` | array | 一维数字数组,一维离散数据 | | `c_y` | array | 一维数字数组,一维连续数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `cond_entropy_dd(d_x, d_y, base)` 声明:function 获取离散变量与离散变量的条件熵 | 参数 | 类型 | 说明 | | ------ | ----- | ---------------------------- | | `d_x` | array | 一维数字数组,一维离散数据 | | `d_y` | array | 一维数字数组,一维离散数据 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `entropy_c(c_x, k, base)` 声明:function 获取连续变量的熵 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `c_x` | array | 一维数字数组,一维连续数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `entropy_d(d_x, base)` 声明:function 获取离散变量的熵 | 参数 | 类型 | 说明 | | ------ | ----- | ---------------------------- | | `d_x` | array | 一维数字数组,一维离散数据 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `mi_cc(c_x, c_y, k, base)` 声明:function 获取连续变量与连续变量的互信息 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `c_x` | array | 一维数字数组,一维连续数据 | | `c_y` | array | 一维数字数组,一维连续数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `mi_cd(c_x, d_y, k, base)` 声明:function 获取连续变量与离散变量的互信息 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `c_x` | array | 一维数字数组,一维连续数据 | | `d_y` | array | 一维数字数组,一维离散数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `mi_dc(d_x, c_y, k, base)` 声明:function 获取离散变量与连续变量的互信息 | 参数 | 类型 | 说明 | | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | `d_x` | array | 一维数字数组,一维离散数据 | | `c_y` | array | 一维数字数组,一维连续数据 | | `k` | integer | 整数,k-近邻估计的 k 参数,计算当前数据点与距离最近的第 k 个数据点之间距离时使用, 一般来说,k 越小,统计误差越大,系统误差越小,k 越大则相反。通常 k 取 3 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `mi_dd(d_x, d_y, base)` 声明:function 获取离散变量与离散变量的互信息 | 参数 | 类型 | 说明 | | ------ | ----- | ---------------------------- | | `d_x` | array | 一维数字数组,一维离散数据 | | `d_y` | array | 一维数字数组,一维离散数据 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real ## `proba_entropy(p, base)` 声明:function 获取给定概率数据的熵 | 参数 | 类型 | 说明 | | ------ | ----- | ---------------------------- | | `p` | array | 一维数字数组,一维概率数据 | | `base` | real | 实数,对数底,取对数时的底数 | 返回:real