I have the following code snippet
classifier = NaiveBayesClassifier.train(train_data)
#classifier.show_most_informative_features(n=20)
results = classifier.classify(test_data)
and the error shows in the following line
results = classifier.classify(test_data)
error:
Traceback (most recent call last):
File "trial_trial.py", line 46, in <module>
results = classifier.classify(test_data)
File "c:\Users\Amr\Anaconda\lib\site-packages\nltk\classify\naivebayes.py", line 88, in classify
return self.prob_classify(featureset).max()
File "c:\Users\Amr\Anaconda\lib\site-packages\nltk\classify\naivebayes.py", line 94, in prob_classify
featureset = featureset.copy()
AttributeError: 'list' object has no attribute 'copy'
I think of extending base class list in python and add copy function but I'm not expert in python and I don't know how to solve this problem.
If you are getting an object that has no attribute error then the reason behind it is because your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
The list.copy method does not work both in python 2.x and python 3.x, I wonder why it is still in the documentation. To achieve the results of copying a list, user the list keyword:
fruits = ['banana', 'cucumber', 'apple', 'water mellon']
my_fruits = list(fruits)
Optionally, you can copy a list by slicing it:
my_fruits_copy = fruits[:]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With