2013-04-28 3 views
0

파이썬에서 arff 라이브러리의 dump 명령을 사용하면 주어진 입력에 따라 arff 파일을 만들 수 있습니다. 명령 : 주어진 데이터에 대한파이썬에서 arff 라이브러리로 생성 된 arff 파일의 공칭 속성

@relation relation1 
@attribute age real 
@attribute hairColor string 
@data 
10,0.2,black 
22,10,yellow 
30,2,black 

:

arff.dump("outputDir", data, relation="relation1", 
      names=['age, fatRatio, hairColor']) 

는 다음 arff를 얻을 수

data = [[10,0.2,'black'],[22,10,'yellow'],[30,2,'black']] 

내 질문은 : 나는 hairColor에 원하는 관련 메커니즘을 통지하는 방법 공칭 속성, 즉 내 arff 헤더가 다음과 같아야합니다.

@relation relation1 
@attribute age real 
@attribute hairColor **nominal** 
@data 
... 
,

답변

0

이 여기에 설명 할 수있는 다른 몇 가지 방법이 있습니다 https://code.google.com/p/arff/wiki/Documentation

내가 나를 위해 더 나은 방법이 권장하는 두 번째 생각이 :

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 

그래서 내가 무엇을 hav

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')]) 
:이 같은 뭔가를 할 수

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 

를 다음 코드 위의 다음 수행 전자는이처럼 내 속성의 각 호칭에 대해 다른 "래퍼"명목 클래스를 생성

관련 문제