-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFeature.py
More file actions
73 lines (61 loc) · 2.1 KB
/
testFeature.py
File metadata and controls
73 lines (61 loc) · 2.1 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
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 21:42:54 2019
@author: Gias
"""
import Tfidf as tfidf
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)
print("Load Data Train")
title = "D:\TA\Stemming\Data_Train\DataTrain1.pickle"
pickle_in = open(title,"rb")
dataTrain = pickle.load(pickle_in)
print("Load Data Test")
title = "D:\TA\Stemming\Data_Test\DataTest1.pickle"
pickle_in = open(title,"rb")
dataTest = pickle.load(pickle_in)
print("Load Feature MI")
title = "D:\TA\Stemming\Data_feature_MI\FeatureMI1.pickle"
pickle_in = open(title,"rb")
featureX = pickle.load(pickle_in)
print("Load Train Index")
title = "D:\TA\Stemming\Index_Data\TrainIndex1.pickle"
pickle_in = open(title,"rb")
train_index = pickle.load(pickle_in)
print("Load Train Index")
title = "D:\TA\Stemming\Index_Data\TestIndex1.pickle"
pickle_in = open(title,"rb")
test_index = pickle.load(pickle_in)
length = 0
while(length<=len(featureX)):
length+=100
feature = []
for i in range (0,length+1):
feature.append(featureX[i].news)
tfTrain = tfidf.getTf(feature,dataTrain) #get TF Value
idfTrain = tfidf.getIdf(feature,dataTrain) #get IDF Value
tfidfTrain = tfidf.getTfidf(tfTrain, idfTrain,feature,dataTrain) #get TF-IDF
tfTest = tfidf.getTf(feature,dataTest)
tfidfTest = tfidf.getTfidf(tfTest, idfTrain,feature,dataTest)
print("Jumlah Feature = ",length+1)
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
print("Akurasi = ",acc,"%")