ashkonf / HybridNaiveBayes

A generalized implementation of the Naive Bayes classifier in Python.
MIT License
25 stars 4 forks source link

Is there anyway to output results to txt or csv? #4

Closed xiejiachen closed 8 years ago

xiejiachen commented 8 years ago

Hi, author.

If we let first 800 rows as train data, and last 200 rows as test data, how to output the prediction results both with train data and test data?

Yours

ashkonf commented 8 years ago

In test.py you can change the variable data_set_slice to 800 to make the code use the first 800 data points as the training set, and set aside the remaining data points as the test set.

To print all the predictions, you can iterate over all the data points at the end of the script and print the result of calling classifier.predict(data_point).

xiejiachen commented 8 years ago

error report: 'NaiveBayesClassifier' object has no attribute 'predict'

After checking source codes carefully, i remain not found function predict....

ashkonf commented 8 years ago

My mistake. I meant "classify"

xiejiachen commented 8 years ago

Is that convenient for you to just give an out example, really thanks!

ashkonf commented 8 years ago

classifier = nb.NaiveBayesClassifier(featurizer) classifier.train(training_set[0], training_set[1]) for data_point in test_set[0]: print classifier.classify(data_point)