當前位置: 首頁>>代碼示例>>Python>>正文


Python classifiers.NaiveBayesClassifier方法代碼示例

本文整理匯總了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 
開發者ID:ManishKV,項目名稱:text_imbalance_multiclass_classifier,代碼行數:23,代碼來源:multiclass_classifier.py

示例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) 
開發者ID:drinksober,項目名稱:ChatBot,代碼行數:18,代碼來源:time_adapter.py

示例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)) 
開發者ID:arnauddelaunay,項目名稱:BotValue-public,代碼行數:15,代碼來源:query_adapter.py

示例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) 
開發者ID:ben-cunningham,項目名稱:poligraph,代碼行數:10,代碼來源:text_parser.py

示例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) 
開發者ID:brandenk514,項目名稱:hal,代碼行數:28,代碼來源:naturalLanguage.py


注:本文中的textblob.classifiers.NaiveBayesClassifier方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。