当前位置: 首页>>代码示例>>Python>>正文


Python Classifier.load方法代码示例

本文整理汇总了Python中classifier.Classifier.load方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.load方法的具体用法?Python Classifier.load怎么用?Python Classifier.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在classifier.Classifier的用法示例。


在下文中一共展示了Classifier.load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_save_load

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import load [as 别名]
    def test_save_load(self):
        sentences = split_sentences(self.text)
        sentencesWithoutStemming = remove_stemming (sentences)
        allBigrams = defaultdict(int)
        for s in sentencesWithoutStemming:
            newBigrams = make_bigrams(s)
            merge_and_sum_bigrams(allBigrams, newBigrams)

        self.classifier.update_joint_apriori(allBigrams)
        
        for k,v in self.classifier.apriori.items():
            print k,v
        
        self.classifier.save('testC')
        newClassifier = Classifier()
        newClassifier.load('testC')
        #self.assertDictEqual(self.classifier.apriori, newClassifier.apriori)
        print '\nCOMPARE\n'
        for k,v in self.classifier.apriori.items():
            print k,v
        for k,v in newClassifier.apriori.items():
            print k,v
        print '\nEND OF COMPARE\n'
开发者ID:chefarov,项目名称:predictNextWord,代码行数:25,代码来源:unittests.py

示例2: main

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import load [as 别名]
def main():
    args = parser.parse_args()
    data_json = read_dataset(args.data)
    random.shuffle(data_json)

    training_set_ratio = 0.7
    training_set_size = int(training_set_ratio * len(data_json) + 0.5)

    training_set = data_json[:training_set_size]
    test_set = data_json[training_set_size:]

    processor = TextProcessor()
    classifier = Classifier(processor)
    classifier.train(training_set)

    print classifier.dump() == Classifier.load(classifier.dump(), processor).dump()
开发者ID:bernardorufino,项目名称:tg-articles,代码行数:18,代码来源:exp.py

示例3: usage

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import load [as 别名]
    classifier = "classifier.pickle"

    opts, args = getopt.getopt(sys.argv[1:], "hc:d:k:s:e:")
    for o, a in opts:
        if o == "-d":
            db = a
        elif o == "-c":
            classifier = a
        elif o == "-k":
            keywords.append(a)
        elif o == "-s":
            start = datetime.strptime(a, "%Y-%M-%d")
        elif o == "-e":
            end = datetime.strptime(a, "%Y-%M-%d")
        else:
            usage()
            sys.exit(0)

    classifier = Classifier.load(classifier)
    aggregator = RetweetWeightedAggregator()

    ts = TweetStore(db)
    for t in ts.get(keywords, start, end):
        s = classifier.classify(t)
        print("%s -- sentiment: %s" % (tweet.to_ascii(t)[tweet.TEXT], "positive" if (s == 1) else "negative"))
        aggregator.add(t, s)

    print("Aggregated sentiment: %f" % aggregator.get_sentiment())
    print("ID of last tweet: %d" % aggregator.get_last_id())
    print("Total number of tweets: %d" % aggregator.get_num())
开发者ID:schuay,项目名称:advanced_internet_computing,代码行数:32,代码来源:dbclassify.py

示例4: Classifier

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import load [as 别名]
## - Comp 4710 - Data Mining
## - Prof: Dr. Carson K. Leung
## - Authors: Trevor Blanchard, Stefan Harris, Brett Small, Sam Peers
## - Sentiment Miner
## - December 10, 2015

## - An interactive classifier

import sys
from classifier import Classifier

print "\nPlease wait while the training data is loaded.."

myClassifier = Classifier()
myClassifier.load()

print "Ready for input"

filename = raw_input("Enter a file name or a directory (type \"quit\" to quit) > ")

while filename != "quit":
    if ".txt" in filename:
        with open(filename, 'r') as infile:
            clsfy = myClassifier.classify(infile)
            if clsfy > 0:
                print "Positive! Weight = {0}".format(clsfy)
            elif clsfy < 0:
                print "Negative! Weight = {0}".format(clsfy)
            elif clsfy == 0:
                print "Undertermined"
    else:
开发者ID:Studentblanchard,项目名称:DataMining,代码行数:33,代码来源:interactive.py


注:本文中的classifier.Classifier.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。