是否可以使用 pyweka 更改 arff 的属性类型?

Is possible to change the type of an attribute from an arff with pyweka?

我有一个这样的 arff :

@relation 'Base de datos modelos 1 y 2'

@attribute BMI numeric
@attribute ROM-PADF-KE_D numeric
@attribute Asym-ROM-PHIR(≥8)_discr {No_Bilateral_Asymmetry,Bilateral_Asymmetry}
@attribute Asym_SLCMJLanding-pVGRF(10percent)_discr {No_Bilateral_Asymmetry,Bilateral_Asymmetry}
@attribute Asym_TJ_Valgus_FPPA(10percent)_discr {No_Bilateral_Asymmetry,Bilateral_Asymmetry}
@attribute DVJ_Valgus_KneeMedialDisplacement_D_discr numeric
@attribute Soft-Tissue_injury_≥4days {No,Yes}

@data
18.716444,33,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,0,No
22.182267,41,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,2,No
25.352783,35,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,1,No
21.332873,33,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,0,No
23.085619,25,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,3,Yes
21.428649,42,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,No_Bilateral_Asymmetry,1,No

我想将“@attribute DVJ_Valgus_KneeMedialDisplacement_D_discr”的数字类型更改为 {0,1,2,3}

可以吗?

您可以为此目的使用 NumericToNominal 过滤器。

你要转换的属性是第6个,所以你需要做这样的事情:

import weka.core.jvm as jvm
from weka.core.converters import load_any_file, save_any_file
from weka.filters import Filter

jvm.start()
data = load_any_file("/some/where/data_in.arff", class_index="last")

f = Filter(classname="weka.filters.unsupervised.attribute.NumericToNominal", options=["-R", "6"])
f.inputformat(data)
filtered = f.filter(data)

save_any_file(filtered, "/some/where/data_out.arff")

jvm.stop()