-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclassifier_bulk.py
51 lines (38 loc) · 1.22 KB
/
classifier_bulk.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
"""
Bulk Train-Test Classifier
========================================
This example uses bulk train-test method of Classifier.
"""
import sklearn.metrics
from jubakit.classifier import Classifier, Schema, Dataset, Config
from jubakit.loader.csv import CSVLoader
import jubakit.logger
# In this example, we enable logging mechanism to show you
# what's going on in jubakit.
jubakit.logger.setup_logger(jubakit.logger.INFO)
# Load a CSV file.
loader = CSVLoader('iris.csv')
# Define a Schema that defines types for each columns of the CSV file.
schema = Schema({
'Species': Schema.LABEL,
}, Schema.NUMBER)
# Display Schema
print('Schema: {0}'.format(schema))
# Create a Dataset.
dataset = Dataset(loader, schema).shuffle()
n_samples = len(dataset)
n_train_samples = int(n_samples / 2)
# Create a Classifier configuration.
cfg = Config()
# Bulk train-test the classifier.
result = Classifier.train_and_classify(
cfg,
dataset[:n_train_samples],
dataset[n_train_samples:],
sklearn.metrics.classification_report
)
print('---- Classification Report -----------------------------------')
print(result)