本文整理汇总了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
示例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
示例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)
示例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()
示例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)
示例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