-
Notifications
You must be signed in to change notification settings - Fork 0
/
classification.py
70 lines (56 loc) · 1.58 KB
/
classification.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
61
62
63
64
65
66
67
68
69
70
from pprint import pprint
# from skmultilearn.dataset import load_dataset
#
#
#
# X_train, y_train, feature_names, label_names = load_dataset('emotions', 'train')
# X_test, y_test, _, _ = load_dataset('emotions', 'test')
#
#
# print(X_train)
# # pprint(label_names)
#
# print(type(y_test))
#
# # pprint(feature_names)
#
# from skmultilearn.problem_transform import BinaryRelevance
# from sklearn.svm import SVC
#
# clf = BinaryRelevance(
# classifier=SVC(gamma='auto'),
# require_dense=[False, True],
# )
#
# clf.fit(X_train, y_train)
#
# print(clf)
#
# prediction = clf.predict(X_test)
#
# pprint(prediction)
#
# import sklearn.metrics as metrics
# print(metrics.hamming_loss(y_test, prediction))
# print(metrics.accuracy_score(y_test, prediction))
from scipy import sparse
from numpy import array
I = array([1,3,1,0,1,3])
J = array([0,3,1,2,0,2])
V = array([4,5,7,9])
from skmultilearn.dataset import load_dataset
X_train, y_train, _, _ = load_dataset('scene', 'train')
X_test, y_test, _, _ = load_dataset('scene', 'test')
from skmultilearn.ext import Meka
meka_classpath = "/opt/meka-release-1.9.0/lib"
meka = Meka(
meka_classifier = "meka.classifiers.multilabel.BCC", # Binary Relevance
weka_classifier = "weka.classifiers.bayes.NaiveBayesMultinomial", # with Naive Bayes single-label classifier
meka_classpath = meka_classpath, #obtained via download_meka
java_command = '/usr/bin/java' # path to java executable
)
meka
meka.fit(X_train, y_train)
predictions = meka.predict(X_test)
from sklearn.metrics import hamming_loss
print(hamming_loss(y_test, predictions))