Why Mallet text classification output the same val

2019-08-29 01:12发布

I am learning Mallet text classification command lines. The output values for estimating differrent classes are all the same 1.0. I do not know where I am incorrect. Can you help?

mallet version: E:\Mallet\mallet-2.0.8RC3

//there is a txt file about cat breed (catmaterial.txt) in cat dir.
//command 1
C:\Users\toshiba>mallet import-dir --input E:\Mallet\testmaterial\cat --output E
:\Mallet\testmaterial\cat.mallet --remove-stopwords

//command 1 output
Labels =
   E:\Mallet\testmaterial\cat

//command 2, save classifier as catClass.classifier
C:\Users\toshiba>mallet train-classifier --input E:\Mallet\testmaterial\cat.mall
et --trainer NaiveBayes --output-classifier E:\Mallet\testmaterial\catClass.clas
sifier

//command 2 output
Training portion = 1.0
Unlabeled training sub-portion = 0.0
Validation portion = 0.0
Testing portion = 0.0

-------------------- Trial 0  --------------------

Trial 0 Training NaiveBayesTrainer with 1 instances
Trial 0 Training NaiveBayesTrainer finished
No examples with predicted label !
No examples with true label !
No examples with predicted label !
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer training data accuracy = 1.0
Trial 0 Trainer NaiveBayesTrainer Test Data Confusion Matrix
No examples with predicted label !
Trial 0 Trainer NaiveBayesTrainer test data precision() = 1.0
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer test data recall() = 1.0
No examples with predicted label !
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer test data F1() = 1.0
Trial 0 Trainer NaiveBayesTrainer test data accuracy = NaN

NaiveBayesTrainer
Summary. train accuracy mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test accuracy mean = NaN stddev = NaN stderr = NaN
Summary. test precision() mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test recall() mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test f1() mean = 1.0 stddev = 0.0 stderr = 0.0

//command 3, estimate classes of the three files about cat, deer and dog. The cat file is the same as the one for cat.mallet
C:\Users\toshiba>mallet classify-dir --input E:\Mallet\testmaterial\test_cat_dir
 --output - --classifier E:\Mallet\testmaterial\catClass.classifier


//command 3 output
file:/E:/Mallet/testmaterial/test_cat_dir/catmaterial.txt               1.0
file:/E:/Mallet/testmaterial/test_cat_dir/deertext.txt          1.0
file:/E:/Mallet/testmaterial/test_cat_dir/dogmaterial.txt               1.0

// why the three classes are all 1.0 ?

C:\Users\toshiba>

Can you help? Thanks.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Update:

Thank you for answer, but still output 1.0 for all files.

My idea was that I put some dog files in dog dir and treated these dog files as instances, trained model, then tested some files in test_dir to see the result.

I tried according to my understanding of your suggestion but still output all same 1.0.

Will you help me with my commandlines below?

In E:\Mallet\train_dir\dog, there are 4 dog txt files(dog 2.txt, dog4.txt,dog5.txt, dogmaterial.txt).

In E:\Mallet\test_dir, there are 9 txt files (cat2.txt, catmaterial.txt, deermaterial.txt, dog3.txt, dog6.txt, dog 2.txt, dog4.txt, dog5.txt, dogmaterial.txt).


C:\Users\toshiba>mallet import-dir --input E:\Mallet\train_dir\dog --output E:\M
allet\classifier_dir\3animal.mallet --remove-stopwords
Labels =
   E:\Mallet\train_dir\dog


C:\Users\toshiba>mallet train-classifier --input E:\Mallet\classifier_dir\3anima
l.mallet --trainer NaiveBayes --output-classifier E:\Mallet\classifier_dir\3anim
alClass.classifier
Training portion = 1.0
Unlabeled training sub-portion = 0.0
Validation portion = 0.0
Testing portion = 0.0                          
-------------------- Trial 0  --------------------

Trial 0 Training NaiveBayesTrainer with 4 instances
Trial 0 Training NaiveBayesTrainer finished
No examples with predicted label !
No examples with true label !
No examples with predicted label !
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer training data accuracy = 1.0
Trial 0 Trainer NaiveBayesTrainer Test Data Confusion Matrix
No examples with predicted label !
Trial 0 Trainer NaiveBayesTrainer test data precision() = 1.0
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer test data recall() = 1.0
No examples with predicted label !
No examples with true label !
Trial 0 Trainer NaiveBayesTrainer test data F1() = 1.0
Trial 0 Trainer NaiveBayesTrainer test data accuracy = NaN

NaiveBayesTrainer
Summary. train accuracy mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test accuracy mean = NaN stddev = NaN stderr = NaN
Summary. test precision() mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test recall() mean = 1.0 stddev = 0.0 stderr = 0.0
Summary. test f1() mean = 1.0 stddev = 0.0 stderr = 0.0


C:\Users\toshiba>mallet classify-dir --input E:\Mallet\test_dir --output - --cla
ssifier E:\Mallet\classifier_dir\3animalClass.classifier

file:/E:/Mallet/test_dir/cat2.txt               1.0
file:/E:/Mallet/test_dir/catmaterial.txt                1.0
file:/E:/Mallet/test_dir/deertext.txt           1.0
file:/E:/Mallet/test_dir/dog%202.txt            1.0
file:/E:/Mallet/test_dir/dog3.txt               1.0
file:/E:/Mallet/test_dir/dog4.txt               1.0
file:/E:/Mallet/test_dir/dog5.txt               1.0
file:/E:/Mallet/test_dir/dog6.txt               1.0
file:/E:/Mallet/test_dir/dogmaterial.txt                1.0
C:\Users\toshiba>

Thank you.

1条回答
放我归山
2楼-- · 2019-08-29 01:42

There are two input options. input-dir treats directories as classes and each file in each directory as an input instance. input-file reads the input file line by line and treats various fields within the line as label and instance data. You are using the files-in-directories input type, so you are creating a classifier with one class and one instance. I'm guessing you want the lines-in-file type.

查看更多
登录 后发表回答