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


Python Classifier.train方法代码示例

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


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

示例1: load_classifier

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
def load_classifier(neighbours, blur_scale, c=None, gamma=None, verbose=0):
    classifier_file = 'classifier_%s_%s.dat' \
            % (blur_scale, neighbours)
    classifier_path = DATA_FOLDER + classifier_file

    if exists(classifier_file):
        if verbose:
            print 'Loading classifier...'

        classifier = Classifier(filename=classifier_path, \
                neighbours=neighbours, verbose=verbose)
    elif c != None and gamma != None:
        if verbose:
            print 'Training new classifier...'

        classifier = Classifier(c=c, gamma=gamma, neighbours=neighbours, \
                verbose=verbose)
        learning_set = load_learning_set(neighbours, blur_scale, \
                verbose=verbose)
        classifier.train(learning_set)
        classifier.save(classifier_path)
    else:
        raise Exception('No soft margin and gamma specified.')

    return classifier
开发者ID:imargon,项目名称:scrapy_demo,代码行数:27,代码来源:create_classifier.py

示例2: main

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
def main():
    try:
        trainingData, tuningData, testData, priorSpam = buildDataSets()
        nbc = Classifier(priorSpam, COUNT_THRESHOLD, SMOOTHING_FACTOR, DEFAULT_PROBABILITY)
        # nbc = Classifier2(priorSpam, 0, .01, None)
        nbc.train(trainingData)

        nbc.classify(testData)
        report(testData)

    except Exception as e:
        print e
        return 5
开发者ID:superdude264,项目名称:SpamFilter,代码行数:15,代码来源:spamFilter.py

示例3: run

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
def run():
	clf= Classifier('breast-cancer-wisconsin.data.txt')
	clf.clf_fit_transform()
	
	clf.default_accuracy_lr()
	
	clf.weight_coefficent_lr()
	clf.SBS_lf()
	# it takes long time to run the Random forest Code ...uncomment to check the result
	# clf.feature_selection_rf()
	clf.PCA()
	clf.pipe_kf_validation()
	clf.clf_learning_curve()
	clf.clf_validation_curve()
	clf.clf_roc_curve()
	
	clf.train()
	clf.l1l2()
	
	
	dest = os.path.join('classifier', 'pkl_objects')
	if not os.path.exists(dest):
		os.makedirs(dest)
	pickle.dump(clf,	open(os.path.join(dest, 'classifier.pkl'), 'wb'),	protocol=2)
开发者ID:thak123,项目名称:ML2016,代码行数:26,代码来源:main.py

示例4: Classifier

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
              ('I had a ton of homework', 'hyperbole'),
              ('If I can’t buy that new game I will die', 'hyperbole')]

nor_tweets = [('I do not like this car', 'normal'),
              ('I like this car', 'normal'),
              ('This view is horrible', 'normal'),
              ('I feel tired this morning', 'normal'),
              ('I am not looking forward to the concert', 'normal'),
              ('The door is black', 'normal'),
              ('I love you', 'normal'),
              ('He is my enemy', 'normal')]

tweets = hyp_tweets + nor_tweets

classifier = Classifier()

classifier.train(tweets)
# for tweet in Fetcher.fetch("hyperbole", 10):
#   print(classifier.classify(tweet))

@app.route('/')
@app.route("/<count>")
def index(count=10):
    tweets = []
    for tweet in Fetcher.fetch("hyperbole", int(count)):
        tweets.append((tweet, classifier.classify(tweet)))
    return render_template('index.html', tweets=set(tweets), count=count)

if __name__ == "__main__":
    app.debug = True
    app.run()
开发者ID:toshle,项目名称:hyperbole,代码行数:33,代码来源:app.py

示例5: test_predict

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
	def test_predict(self):
		x = Classifier()
		x.train()
		predicted = x.predict("train", "directory")
		actual = [(u'intermediate test', 2), (u'elementary test', 1), (u'advanced test', 0)]
		self.assertEqual(predicted, actual)
开发者ID:kinimesi,项目名称:rscore,代码行数:8,代码来源:test_Classifier.py

示例6: load_learning_set

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import train [as 别名]
# Load learning set and test set
learning_set = load_learning_set(neighbours, blur_scale, verbose=1)
test_set = load_test_set(neighbours, blur_scale, verbose=1)

# Perform a grid-search to find the optimal values for C and gamma
C = [float(2 ** p) for p in xrange(-5, 16, 2)]
Y = [float(2 ** p) for p in xrange(-15, 4, 2)]

results = []
best = (0,)
i = 0

for c in C:
    for y in Y:
        classifier = Classifier(c=c, gamma=y, neighbours=neighbours, verbose=1)
        classifier.train(learning_set)
        result = classifier.test(test_set)

        if result > best[0]:
            best = (result, c, y, classifier)

        results.append(result)
        i += 1
        print '%d of %d, c = %f, gamma = %f, result = %d%%' \
              % (i, len(C) * len(Y), c, y, int(round(result * 100)))

i = 0
s = '     c\y'

for y in Y:
    s += ' | %f' % y
开发者ID:imargon,项目名称:scrapy_demo,代码行数:33,代码来源:find_svm_params.py


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