當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。