本文整理汇总了Python中tgrocery.Grocery.save方法的典型用法代码示例。如果您正苦于以下问题:Python Grocery.save方法的具体用法?Python Grocery.save怎么用?Python Grocery.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tgrocery.Grocery
的用法示例。
在下文中一共展示了Grocery.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def train():
print 'train start '+'.'*30
#grocery=Grocery('sample')
grocery=Grocery('version1.0')
grocery.train(trainlist)
grocery.save()
print 'train end '+'.'*30
示例2: tGrocery
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def tGrocery():
outFile = open('testResult.tmp', 'w')
[trainingSet, benchmark] = pickle.load(open('SampleSeg.pk'))
testingSet = []
correctLabel = []
for i in xrange(len(benchmark)):
print '%d out of %d' % (i, len(benchmark))
testingSet.append(benchmark[i][1])
correctLabel.append(benchmark[i][0])
grocery = Grocery('test')
grocery.train(trainingSet)
grocery.save()
# load
new_grocery = Grocery('test')
new_grocery.load()
Prediction = []
for i in xrange(len(testingSet)):
print '%d out of %d' % (i, len(testingSet))
prediction = new_grocery.predict(testingSet[i])
Prediction.append(prediction)
temp = correctLabel[i] + '<-->' + prediction + ' /x01' + testingSet[i] + '\n'
outFile.write(temp)
correct = 0
for i in xrange(len(Prediction)):
print Prediction[i], correctLabel[i],
if Prediction[i] == correctLabel[i]:
correct += 1
print 'Correct'
else:
print 'False'
print 'Correct Count:', correct
print 'Accuracy: %f' % (1.0 * correct / len(Prediction))
示例3: GroceryModel
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
class GroceryModel(object):
def __init__(self):
self.grocery = Grocery('TextClassify')
def train(self,train_file):
f = open(train_file,'r')
line = f.readline().decode('utf8')
dataset = []
while line:
tmp = line.split('\t')
dataset.append((tmp[0],''.join(tmp[1:])))
line = f.readline().decode('utf8')
f.close()
self.grocery.train(dataset)
self.grocery.save()
def load_model(self):
self.grocery.load()
def test(self,test_src):
self.load_model()
f = open(test_src,'r')
line = f.readline().decode('utf8')
dataset = []
while line:
tmp = line.split('\t')
dataset.append((tmp[0],''.join(tmp[1:])))
line = f.readline().decode('utf8')
f.close()
result = self.grocery.test(dataset)
print result
def predict(self,text):
print self.grocery.predict(text)
示例4: __train__model__
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def __train__model__():
dataframe = pd.read_excel(Classify.__FILE_PATH__)
data = dataframe[[u'类型', u'释义']]
train_data = [(x[0],x[1]) for x in data.values]
grocery = Grocery('Classify')
grocery.train(train_data)
grocery.save()
Classify.__MODEL__ = grocery
示例5: test_grocery
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def test_grocery():
grocery = Grocery('model_redian')
grocery.train('trdata_4.txt')
grocery.save()
new_grocery = Grocery('model_redian')
new_grocery.load()
test_result = new_grocery.test('tedata_4.txt')
print test_result.accuracy_labels
print test_result.recall_labels
test_result.show_result()
示例6: test_main
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def test_main(self):
grocery = Grocery(self.grocery_name)
grocery.train(self.train_src)
grocery.save()
new_grocery = Grocery('test')
new_grocery.load()
assert grocery.get_load_status()
assert grocery.predict('考生必读:新托福写作考试评分标准') == 'education'
# cleanup
if self.grocery_name and os.path.exists(self.grocery_name):
shutil.rmtree(self.grocery_name)
示例7: sentiment_train
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def sentiment_train(gro_name, train_set):
"""
:param gro_name:
:param train_set:
:return:
"""
gro_ins = Grocery(gro_name)
# gro_ins.load()
gro_ins.train(train_set)
print("Is trained? ", gro_ins.get_load_status())
gro_ins.save()
示例8: MyGrocery
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
class MyGrocery(object):
def __init__(self, name):
super(MyGrocery, self).__init__()
self.grocery = Grocery(name)
self.loaded = False
self.correct = 1.0
def train(self, src):
lines = []
for line in csv.reader(open(src)):
label, s = line[0],line[1]
text = s.decode('utf8')
lines.append((label, text))
self.grocery.train(lines)
def save_model(self):
self.grocery.save()
def train_and_save(self, src):
self.train(src)
self.save_model()
def load_model(self):
if not self.loaded:
self.grocery.load()
self.loaded = True
def predict(self, text):
self.load_model()
return self.grocery.predict(text)
def test(self, src):
self.load_model()
total, wrong_num = 0.0, 0.0
for line in csv.reader(open(src)):
total += 1
if line[0] != self.predict(line[1]):
wrong_num += 1
print "load test file from " + src
correct = (total - wrong_num ) / total
self.correct = correct
print "total: %d , wrong_num: %d, success percentage: %f" %(total, wrong_num, correct)
result = dict(type="test", total=total, wrong_num=wrong_num, correct=correct)
return json.dumps(result)
示例9: Grocery
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
from tgrocery import Grocery
# 新开张一个杂货铺(别忘了取名)
grocery = Grocery('sample')
# 训练文本可以用列表传入
train_src = [
('education', '名师指导托福语法技巧:名词的复数形式'),
('education', '中国高考成绩海外认可 是“狼来了”吗?'),
('sports', '图文:法网孟菲尔斯苦战进16强 孟菲尔斯怒吼'),
('sports', '四川丹棱举行全国长距登山挑战赛 近万人参与')
]
grocery.train(train_src)
# 也可以用文件传入(默认以tab为分隔符,也支持自定义)
#grocery.train('train_ch.txt')
# 保存模型
grocery.save()
# 加载模型(名字和保存的一样)
new_grocery = Grocery('sample')
new_grocery.load()
# 预测
new_grocery.predict('考生必读:新托福写作考试评分标准')
#education
# 测试
test_src = [
('education', '福建春季公务员考试报名18日截止 2月6日考试'),
('sports', '意甲首轮补赛交战记录:米兰客场8战不败国米10年连胜'),
]
new_grocery.test(test_src)
# 输出测试的准确率
#0.5
示例10: train
# 需要导入模块: from tgrocery import Grocery [as 别名]
# 或者: from tgrocery.Grocery import save [as 别名]
def train(path,name):
grocery = Grocery(name)
grocery.train(path)
grocery.save()