-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathweight_shogun.py
60 lines (49 loc) · 1.83 KB
/
weight_shogun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
"""
Using Weight Service
====================
This example illustrates how to use Weight engine to debug fv_converter
behavior (i.e. `converter` section of the config file).
"""
from jubakit.weight import Weight, Schema, Dataset, Config
from jubakit.loader.csv import CSVLoader
# Load a CSV file.
loader = CSVLoader('shogun.train.csv')
# Create a Dataset; schema will be auto-predicted.
dataset = Dataset(loader)
# Create a Weight Service.
cfg = Config()
weight = Weight.run(cfg)
# Show extracted features. As we use `update` method, weights are
# updated incrementally.
print('==== Features (online TF-IDF) ========================')
for (idx, result) in weight.update(dataset):
print('Raw Data:')
print('\tfamily_name: {0}'.format(dataset.get(idx)['family_name']))
print('\tfirst_name: {0}'.format(dataset.get(idx)['first_name']))
print('Datum:')
print('\t{0}'.format(dataset[idx]))
print('Features:')
for f in result:
print('\t{0}\t{1}'.format(f.key, f.value))
print('---------------------------------------')
# Show extracted features. This time we use `calc_weight`, so weights
# for each feature is calculated by using weights updated by the above
# code (`update`).
print('==== Features (batch TF-IDF) ========================')
for (idx, result) in weight.calc_weight(dataset):
print('Raw Data:')
print('\tfamily_name: {0}'.format(dataset.get(idx)['family_name']))
print('\tfirst_name: {0}'.format(dataset.get(idx)['first_name']))
print('Datum:')
print('\t{0}'.format(dataset[idx]))
print('Features:')
for f in result:
print('\t{0}\t{1}'.format(f.key, f.value))
print('---------------------------------------')
# Save the model.
weight.save("shogun")
# Stop the service.
weight.stop()