当前位置: 首页>>代码示例>>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;未经允许,请勿转载。