如何使用 FSelector 包正确计算所有权重?
How to properly calculate all weights with FSelector package?
我正在尝试使用 FSelector 包计算 R 中数据集的权重。数据取from this location.
data = read.csv("filepath/Indian Liver Patient Dataset (ILPD).csv")
names(data)<-c("Age","Gender", "TB", "DB", "Alkphos", "Sgpt", "Sgot", "TP", "ALB", "A/G Ratio", "Selector")
library(FSelector)
weights <- gain.ratio(Selector ~., data)
print(weights)
我无法计算所有权重。当我使用 gain.ratio
函数时,Age
权重为 NaN。当我改用 chi.squared
函数时,Age
和 A/G Ratio
都是零。当我从 data
中取出前 200 个元素并计算权重时,其中只有五个正确计算,其他都是零或 NaN。
我尝试通过 data <- na.omit(data)
从数据中删除错误的元素,但它并没有改变结果。
如何正确计算权重?
下面是重量打印的示例。
Age 0.0000000
Gender 0.1304229
TB 0.3281865
DB 0.3238010
Alkphos 0.2965842
Sgpt 0.2734633
Sgot 0.3120432
TP 0.2504747
ALB 0.3051724
A/G Ratio 0.0000000
零是特征重要性的有效值 -- 这意味着该特征没有关于分类目标的任何信息。 NaN 是由 FSelector 中的错误引起的,如果特征不携带任何信息,该错误会除以 0。我已经在开发版本中修复了这个问题。
名称 "A/G Ratio" 不是有效的 R 标识符,因此会导致某些方法出现问题。在修复此问题并安装 FSelector 开发版本的代码下方。
data = read.csv("Indian\ Liver\ Patient\ Dataset\ (ILPD).csv")
names(data)<-c("Age","Gender", "TB", "DB", "Alkphos", "Sgpt", "Sgot", "TP", "ALB", "AGRatio", "Selector")
library(devtools)
install_github("larskotthoff/fselector")
library(FSelector)
weights = gain.ratio(Selector~., data)
print(weights)
weights = chi.squared(Selector~., data)
print(weights)
输出:
attr_importance
Age 0.00000000
Gender 0.01539699
TB 0.09711392
DB 0.11547683
Alkphos 0.06593879
Sgpt 0.06566624
Sgot 0.07667241
TP 0.08836895
ALB 0.07766682
AGRatio 0.15403574
attr_importance
Age 0.0000000
Gender 0.1304229
TB 0.3281865
DB 0.3238010
Alkphos 0.2965842
Sgpt 0.2734633
Sgot 0.3120432
TP 0.2504747
ALB 0.3051724
AGRatio 0.0000000
我正在尝试使用 FSelector 包计算 R 中数据集的权重。数据取from this location.
data = read.csv("filepath/Indian Liver Patient Dataset (ILPD).csv")
names(data)<-c("Age","Gender", "TB", "DB", "Alkphos", "Sgpt", "Sgot", "TP", "ALB", "A/G Ratio", "Selector")
library(FSelector)
weights <- gain.ratio(Selector ~., data)
print(weights)
我无法计算所有权重。当我使用 gain.ratio
函数时,Age
权重为 NaN。当我改用 chi.squared
函数时,Age
和 A/G Ratio
都是零。当我从 data
中取出前 200 个元素并计算权重时,其中只有五个正确计算,其他都是零或 NaN。
我尝试通过 data <- na.omit(data)
从数据中删除错误的元素,但它并没有改变结果。
如何正确计算权重?
下面是重量打印的示例。
Age 0.0000000
Gender 0.1304229
TB 0.3281865
DB 0.3238010
Alkphos 0.2965842
Sgpt 0.2734633
Sgot 0.3120432
TP 0.2504747
ALB 0.3051724
A/G Ratio 0.0000000
零是特征重要性的有效值 -- 这意味着该特征没有关于分类目标的任何信息。 NaN 是由 FSelector 中的错误引起的,如果特征不携带任何信息,该错误会除以 0。我已经在开发版本中修复了这个问题。
名称 "A/G Ratio" 不是有效的 R 标识符,因此会导致某些方法出现问题。在修复此问题并安装 FSelector 开发版本的代码下方。
data = read.csv("Indian\ Liver\ Patient\ Dataset\ (ILPD).csv")
names(data)<-c("Age","Gender", "TB", "DB", "Alkphos", "Sgpt", "Sgot", "TP", "ALB", "AGRatio", "Selector")
library(devtools)
install_github("larskotthoff/fselector")
library(FSelector)
weights = gain.ratio(Selector~., data)
print(weights)
weights = chi.squared(Selector~., data)
print(weights)
输出:
attr_importance
Age 0.00000000
Gender 0.01539699
TB 0.09711392
DB 0.11547683
Alkphos 0.06593879
Sgpt 0.06566624
Sgot 0.07667241
TP 0.08836895
ALB 0.07766682
AGRatio 0.15403574
attr_importance
Age 0.0000000
Gender 0.1304229
TB 0.3281865
DB 0.3238010
Alkphos 0.2965842
Sgpt 0.2734633
Sgot 0.3120432
TP 0.2504747
ALB 0.3051724
AGRatio 0.0000000