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


Python Grocery.save方法代码示例

本文整理汇总了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
开发者ID:jizhihang,项目名称:adavanced-aritificial-intelligence,代码行数:9,代码来源:train.py

示例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))
开发者ID:haomingchan0811,项目名称:iPIN,代码行数:34,代码来源:prepData.py

示例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)
开发者ID:TimePi,项目名称:forwork,代码行数:36,代码来源:SuperModel.py

示例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
开发者ID:TimePi,项目名称:Python,代码行数:12,代码来源:Classify.py

示例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()
开发者ID:SwoJa,项目名称:ruman,代码行数:12,代码来源:grocery.py

示例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)
开发者ID:SHENbeyond,项目名称:TextGrocery,代码行数:13,代码来源:runtests.py

示例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()
开发者ID:wac81,项目名称:LSI-for-ChineseDocument,代码行数:14,代码来源:SentimentOne.py

示例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)
开发者ID:henryluki,项目名称:word_filter,代码行数:47,代码来源:classify.py

示例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
开发者ID:zhaiduo,项目名称:tgrocery-docs,代码行数:32,代码来源:fastTest.py

示例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()
开发者ID:Gbacillus,项目名称:crawler_fg,代码行数:6,代码来源:classify.py


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