有几种不同的方式在这里做这样概括:
我觉得对我来说更好的方法是第二个这建议是:
arff_writer = arff.Writer(fname, relation='diabetics_data', names)
arff_writer.pytypes[arff.nominal] = '{not_parasite,parasite}'
arff_writer.write([arff.nominal('parasite')])
如果你看看在代码为arff.nominal,它的定义是这样的:
class Nominal(str):
"""Use this class to wrap strings which are intended to be nominals
and shouldn't have enclosing quote signs."""
def __repr__(self):
return self
所以我有大功告成创建每个标称不同的“包装”标称类属性我这样的:
class ZipCode(str):
"""Use this class to wrap strings which are intended to be nominals
and shouldn't have enclosing quote signs."""
def __repr__(self):
return self
,然后按照上面的代码,你可以做这样的事情:
arff_writer = arff.Writer(fname, relation='neighborhood_data', names)
arff_writer.pytypes[type(myZipCodeObject)] = '{85104,84095}'
# then write out the rest of your attributes...
arff_writer.write([arff.nominal('parasite')])