2026a
# fscchi2
使用卡方检验进行分类的单变量特征排序
函数库: TyMachineLearning
# 语法
idx = fscchi2(X,Y)
# 说明
idx, scores = fscchi2(X,Y)使用响应变量 Y 对 X 中的预测变量进行排名。示例
# 示例
矩阵中的排名预测变量
加载ionosphere数据集。
using TyMachineLearning
using CSV
using DataFrames
file = joinpath(pkgdir(TyMachineLearning), "data/Classification/ionosphere.csv")
ionosphere = CSV.read(file, DataFrame; header=false)
ionosphere包含预测变量 X 和响应变量 Y 。
使用卡方检验对预测变量进行排名。
X = ionosphere[:, 1:34]
y = ionosphere[:, 35]
idx, scores= fscchi2(X, y)
(Int32[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 … 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], [16.366996717773333, 14.913876700963753, 7.581679975109774, 7.407002868192832, 6.233614687868994, 5.540061228485755, 5.496360590795849, 5.234131547211019, 5.232564261570626, 5.174300280847413 … 2.5822342699590544, 2.2535265025304594, 1.5855680876007892, 1.4606691292346092, 1.3886304418516835, 1.1414466846674078, 0.7570402982144944, 0.6847190999367618, 0.4261654427316808, NaN])
# 输入参数
X - 预测数据矩阵、数组
预测数据,指定为矩阵。X 的每一行对应一个观测值,每一列对应一个预测变量。
数据类型: Vector Matrix | Array
Y - 响应变量向量、数组
响应变量,指定为数字向量、分类向量、逻辑向量、字符数组、字符串数组或字符向量的单元数组。Y 的每一行表示 X 的对应行的分类。
数据类型: Vector | Array
# 输出参数
idx - 输出值向量
按预测变量重要性排序的预测变量指数。
数据类型: Vector
scores - 输出值向量
预测变量分数。
数据类型: Vector