Search code examples
csvnaivebayesmallet

MALLET - How to pass the csv file which contains word count to näive bayes in mallet?


I have created the CSV file which contains label name and word frequency.

e.g.

    0, 4.0, 0.0, 0.0, 1.0, 0.0

    0, 0.0, 1.0, 2.0, 0.0, 0.0

    1, 1.0, 0.0, 0.0, 0.0, 3.0

Where the index zero represents the label (0 and 1)

My question is, How to import this kind CSV file into mallet to generate instance list? How to pass this file to Näive Bayes Classifier?


Solution

  • I found the answer to my own question.

    In mallet, there are some pipes which create CSV to feature vector.

        pipeList.add(new Csv2Array());
        pipeList.add(new Target2Label());
        pipeList.add(new Array2FeatureVector());
    

    Output for above example: 0 and 1: It takes as target name.

    for the first line: 1(1)=4.0

    2(2)=0.0

    3(3)=0.0

    4(4)=1.0 5(5)=0.0

    same for other two lines.