2012-11-10 5 views
2

JavaML 라이브러리를 사용하여 SparseInstace 객체를 만들었습니다. 일부 인스턴스에 값을 넣었지만 레이블을 할당 할 솔루션을 찾을 수 없었습니다. 예를 들어, 인스턴스는인스턴스 객체에 레이블 (객체 이름) 추가하기

{{2=1.0, 4=2.2};null} 

과 같이 생성됩니다. "null"영역 대신 특정 문자열 값을 추가하려고합니다. 나는 instaces에이 라벨 (개체 이름)를 추가 할 수있는 방법

package helloworld; 

import java.io.IOException; 
import net.sf.javaml.core.Dataset; 
import net.sf.javaml.core.DefaultDataset; 
import net.sf.javaml.core.Instance; 
import net.sf.javaml.core.SparseInstance; 
import net.sf.javaml.matrix.Matrix; 
import net.sf.javaml.tools.InstanceTools; 
import net.sf.javaml.tools.data.FileHandler; 

public class WekaT2 { 

public static void main(String[] args) throws IOException, Exception { 

    Dataset data = new DefaultDataset(); 
    Instance tmpInstance = new SparseInstance(); 

     tmpInstance.put(2, 1.0); 
     tmpInstance.put(4, 2.2); 
     data.add(tmpInstance);  
    } 
} 

http://java-ml.sourceforge.net/api/0.1.7/net/sf/javaml/core/SparseInstance.html

: 여기 내 코드는?

+0

기계 학습 용어의 샘플 분류에서와 같이 "등급 레이블"을 의미합니까? 또는 나중에 인스턴스를 인식 할 수 있도록 "인스턴스 이름"을 의미합니까? – Zero3

답변

1

설정하려는 것은 문서에 명시된대로 클래스 레이블 또는 클래스 값이라고합니다. setClassValue(java.lang.Object value) 샘플 사용이

Instance tmpInstance = new SparseInstance(); 
    tmpInstance.put(2, 1.0); 
    tmpInstance.put(4, 2.2); 
    tmpInstance.setClassValue("positive"); 
+0

http://java-ml.sourceforge.net/content/creating-dataset – JoshuaJeanThree

0

당신은 다음과 같은 생성자를 사용할 수있는 것 당신은 다음과 같은 방법을 사용할 수 있습니다 : JLabel의 같은 ​​

public SparseInstance(int noAttributes, 
      double defaultValue, 
      java.lang.Object classValue) 

및 레이블을 지정하는 객체를 사용, 그것은 할 수있는 일 , 문자열, JButton의

예를 들어

:

Instance tmpInstance = new SparseInstance(); 

    tmpInstance.put(2, 1.0, "myLabel"); 

인사말

+0

이 방법은 사실이 아닙니다. Put 함수는 이와 같은 인수를 취하지 않습니다. – JoshuaJeanThree

+0

자, 이유가 있습니다, SpareInstance를 인스턴스로 캐스팅 한 것으로 보입니다. 아마도 SparseInstace에서 작업 할 수 있습니다. 그것을 좋아하십시오 : SparseInstance tmpInstance = new SparseInstance(); tmpInstance.put (2, 1.0, "myLabel"); –