本文整理匯總了Python中textblob.classifiers.NaiveBayesClassifier方法的典型用法代碼示例。如果您正苦於以下問題:Python classifiers.NaiveBayesClassifier方法的具體用法?Python classifiers.NaiveBayesClassifier怎麽用?Python classifiers.NaiveBayesClassifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類textblob.classifiers
的用法示例。
在下文中一共展示了classifiers.NaiveBayesClassifier方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_classifier
# 需要導入模塊: from textblob import classifiers [as 別名]
# 或者: from textblob.classifiers import NaiveBayesClassifier [as 別名]
def create_classifier(doc,class_freq):
## iterates through all classes in dataset
for i in class_freq:
## create a copy of dataframe
temp_doc = doc.copy()
## assign class as '-1' to all other classes.
temp_doc.category[temp_doc['category'] != class_freq[i]] = '-1'
temp_doc = temp_doc.values.tolist()
## training classifier on the temp_doc
classifier = NaiveBayesClassifier(temp_doc)
# save the classifier on disk
with open('classifier_'+i+'.pkl', 'wb') as fid:
cPickle.dump(classifier, fid)
## reassign doc with the new reduced dataset
doc = doc[doc['category'] != class_freq[i]].copy()
## to track time taken in creating classifiers
示例2: __init__
# 需要導入模塊: from textblob import classifiers [as 別名]
# 或者: from textblob.classifiers import NaiveBayesClassifier [as 別名]
def __init__(self, **kwargs):
super(TimeLogicAdapter, self).__init__(**kwargs)
training_data = [
("what time is it", 1),
("do you know the time", 1),
("do you know what time it is", 1),
("what is the time", 1),
("do you know the time", 0),
("it is time to go to sleep", 0),
("what is your favorite color", 0),
("i had a great time", 0),
("what is", 0)
]
self.classifier = NaiveBayesClassifier(training_data)
示例3: __init__
# 需要導入模塊: from textblob import classifiers [as 別名]
# 或者: from textblob.classifiers import NaiveBayesClassifier [as 別名]
def __init__(self, **kwargs):
super(QueryAdapter, self).__init__(**kwargs)
training_file = '%s/../database/%s.json' % (
os.path.dirname(os.path.realpath(inspect.getfile(self.__class__))),
kwargs.get('training_file_for_query')
)
training_database = json.load(open(training_file))['data']
training_data = [(data,int(classe)) for classe in ["0", "1"] for data in training_database[classe]]
self.classifier = NaiveBayesClassifier(training_data)
self.partners = Database('partners_fake', parse_db=True) #default fixed to partners
self.fields = Database('fields') #lexical fields of different features in db
self.clf = self.train_feature_finder(self.fields.db, RandomForestClassifier(n_estimators=20))
示例4: train
# 需要導入模塊: from textblob import classifiers [as 別名]
# 或者: from textblob.classifiers import NaiveBayesClassifier [as 別名]
def train(self):
rows = []
with open('test_data.csv', 'r') as fp:
data = csv.reader(fp)
for row in data:
rows.append((row[0], row[1], ))
self.cl = NaiveBayesClassifier(rows)
示例5: __init__
# 需要導入模塊: from textblob import classifiers [as 別名]
# 或者: from textblob.classifiers import NaiveBayesClassifier [as 別名]
def __init__(self):
self.features_set = []
self.application_tag = "application"
self.timezone_tag = "timezone"
self.location_tag = "location"
self.weather_tomorrow_tag = "weather tomorrow"
self.weather_tag = "weather"
self.distance_tag = "distance"
self.current_distance_from_tag = "distance from current loc"
self.elevation_tag = "elevation"
self.system_tag = "system"
self.name_tag = "name"
self.train_hal()
random.shuffle(self.features_set)
split = int(len(self.features_set)) - int(len(self.features_set) / 4)
train_set, test_set = self.features_set[:split], self.features_set[split:]
if os.path.isfile('request_classifier.pickle'):
self.classifier = self.load_classifier() # Load classifier so training does not have to occur on every run
else:
print(len(self.features_set))
print("Training...")
self.classifier = NaiveBayesClassifier(train_set)
print(self.classifier.accuracy(test_set))
print("Done")
self.save_classifier(self.classifier)