-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadModel.py
More file actions
80 lines (67 loc) · 2.49 KB
/
LoadModel.py
File metadata and controls
80 lines (67 loc) · 2.49 KB
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
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-1
"""
Created on Fri May 24 22:16:58 2019
@author: Gias
"""
import time
import pickle
import SvmClassification as cl
startTime = time.time()
totalAcc = 0
print("Load Class Value")
pickle_in = open("ClassValue.pickle","rb")
arr = pickle.load(pickle_in)
for i in range (1,6):
# =============================================================================
# print("Load Data Train")
# title = "D:\TA\Stopword\Data_Train\DataTrain"+str(i)+".pickle"
# pickle_in = open(title,"rb")
# dataTrain = pickle.load(pickle_in)
# =============================================================================
# =============================================================================
#
# print("Load Data Test")
# title = "D:\TA\Stopword\Data_Test\DataTest"+str(i)+".pickle"
# pickle_in = open(title,"rb")
# dataTest = pickle.load(pickle_in)
# =============================================================================
print("Load Feature MI")
title = "D:\TA\Stemming\Data_feature_MI\FeatureMI"+str(i)+".pickle"
pickle_in = open(title,"rb")
feature = pickle.load(pickle_in)
print("Load TFIDF Train")
title = "D:\TA\Stemming\Data_TFIDF\TFIDFTrain"+str(i)+".pickle"
pickle_in = open(title,"rb")
tfidfTrain = pickle.load(pickle_in)
print("Load TFIDF Test")
title = "D:\TA\Stemming\Data_TFIDF\TFIDFTest"+str(i)+".pickle"
pickle_in = open(title,"rb")
tfidfTest = pickle.load(pickle_in)
print("Load Train Index")
title = "D:\TA\Stemming\Index_Data\TrainIndex"+str(i)+".pickle"
pickle_in = open(title,"rb")
train_index = pickle.load(pickle_in)
print("Load Test Index")
title = "D:\TA\Stemming\Index_Data\TestIndex"+str(i)+".pickle"
pickle_in = open(title,"rb")
test_index = pickle.load(pickle_in)
print("Klasifikasi ke-", i)
xTrain, xTest = tfidfTrain, tfidfTest
p, r = [], []
for c, y in enumerate(arr):
yTrain, yTest = y[train_index], y[test_index]
predictValue = cl.classification(xTrain, yTrain, xTest)
p.append(predictValue)
r.append(yTest)
tot, acc = 0, 0
for x in range(len(p)):
for y in range(len(p[x])):
if (p[x][y] == r[x][y]):
acc+=1
tot+=1
acc = (acc/tot) * 100
totalAcc+=acc
print("Akurasi = ",acc,"%")
avg = totalAcc/5
print("Rata-Rata Akurasi Model = ",avg,"%")
print('Time: ',time.time()-startTime,'second')