-
Notifications
You must be signed in to change notification settings - Fork 0
/
Merge_Data.py
1309 lines (889 loc) · 45.1 KB
/
Merge_Data.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from System_non_maintainability.Folders import *
import json
import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model
import seaborn as sns
from System_non_maintainability.Measures import *
from sklearn.svm import OneClassSVM
from sklearn.externals import joblib
import pandas as pd
import csv
from collections import OrderedDict
import seaborn as sns
import time
from System_non_maintainability.Thresholds import *
class MergeData:
measures=[]
def __init__(self,measures):
MergeData.measures=measures
'''
method which plot the distribution of all classes of the percentage of the releases that
the classes has changes to the total releases that the classes has appeared
'''
def plot_distribution_changes(self,projects):
data=[]
for project in projects:
change_folder('Results_Classes_'+project)
with open("changes_dropped.json",'r')as handle:
changes_dropped=json.load(handle)
with open("changes_non_dropped.json",'r')as handle:
changes_non_dropped=json.load(handle)
for clas in changes_dropped:
if changes_dropped[clas]['total']>0:
value=changes_dropped[clas]['changes']/changes_dropped[clas]['total']
data.append(value)
for clas in changes_non_dropped:
if changes_non_dropped[clas]['total']>0:
value=changes_non_dropped[clas]['changes']/changes_non_dropped[clas]['total']
data.append(value)
move_initial_folder()
change_folder("Results_Merge_Data")
sns.distplot(data,kde=False,rug=False)
plt.savefig("distribution of total changes")
plt.clf()
'''
method which produces three jsons for the training data
first json contains first values of measures of training data
second json contains last values of measures of training data
thrid json contains final coefs of measures of training data
'''
def create_model_data(self):
projects=[]
projects.append('apache_struts')
projects.append("spring-projects_spring-framework")
start_values_data={}
end_values_data={}
coefs_data={}
measures=return_meas_per_prop()
thres=set_thresholds_measures(self)
count=0
count1=0
for project in projects:
change_folder("Results_Classes_"+project)
with open("recalc_dropped_data.json",'r')as handle:
recalc_data=json.load(handle)
with open("final_coefs_dropped.json",'r')as handle:
final_coefs=json.load(handle)
with open("dropped_classes_start_stop.json",'r')as handle:
limits=json.load(handle)
with open("anomalies.json",'r')as handle:
anomalies=json.load(handle)
with open("filter_classes.json",'r')as handle:
filter=json.load(handle)
with open("short_life_classes.json",'r')as handle:
short_life=json.load(handle)
for clas in recalc_data:
if clas not in short_life and clas in filter and clas not in anomalies:
end_timeline=limits[clas][2]
start_timeline=limits[clas][0]
for property in measures:
meas_values={}
flag=False
if property not in start_values_data:
start_values_data[property]={}
end_values_data[property]={}
coefs_data[property]={}
count_meas=0
for measure in measures[property]:
if measure not in start_values_data[property]:
start_values_data[property][measure]=[]
end_values_data[property][measure]=[]
coefs_data[property][measure]=[]
first_value=recalc_data[clas][start_timeline]['Metrics '+measure][0]
last_value=recalc_data[clas][end_timeline]["Metrics "+measure][-1]
coef=round(final_coefs[clas][measure],4)
if property=="cohesion":
start_values_data[property][measure].append(first_value)
end_values_data[property][measure].append(last_value)
coefs_data[property][measure].append(coef)
if property !="cohesion":
meas_values[measure]=[first_value,last_value,coef]
if property !="documentation":
if last_value>thres[measure]:
flag=True
else:
if last_value>thres[measure]:
count_meas+=1
if count_meas==len(measures[property]):
flag=True
if property !="cohesion":
if flag==True:
count+=1
for measure in meas_values:
start_values_data[property][measure].append(meas_values[measure][0])
end_values_data[property][measure].append(meas_values[measure][1])
coefs_data[property][measure].append(meas_values[measure][2])
move_initial_folder()
change_folder("Training")
with open("start_data_first_values.json",'w')as outfile:
json.dump(start_values_data,outfile)
with open("start_data_end_values.json",'w')as outfile:
json.dump(end_values_data,outfile)
with open("start_data_coefs.json",'w')as outfile:
json.dump(coefs_data,outfile)
'''
method which produces a json with the last values for every measure
of training data
'''
def find_last_appear(self):
move_initial_folder()
projects=[]
projects.append('apache_struts')
projects.append('spring-projects_spring-framework')
measures=return_measures()
last_values={}
for project in projects:
change_folder("Results_Classes_"+project)
with open("dropped_classes_start_stop.json",'r')as handle:
dropped_limits=json.load(handle)
with open("classes_data_measures_dropped.json",'r')as handle:
dropped_data=json.load(handle)
with open("short_life_classes.json",'r')as handle:
short_classes=json.load(handle)
with open("filter_classes.json",'r')as handle:
filter=json.load(handle)
with open("anomalies.json",'r')as handle:
anomalies=json.load(handle)
for clas in dropped_data:
for measure in measures:
if measure not in last_values:
last_values[measure]=[]
end_timeline=dropped_limits[clas][2]
value=dropped_data[clas][end_timeline]['Metrics '+measure][-1]
last_values[measure].append(value)
move_initial_folder()
change_inside_folder("Results_Merge_Data")
with open("last_values.json",'w')as outfile:
json.dump(last_values,outfile)
'''
method which plot the distributions of last values of training data for all metrics
'''
def plot_distribution_last_appear(self):
change_folder("Results_Merge_Data")
with open("last_values.json",'r')as handle:
last_values=json.load(handle)
change_inside_folder("distribution_last_values")
recal_last_values={}
for measure in last_values:
last_values[measure].sort()
t=last_values[measure]
recal_last_values[measure]=t[0:int(0.95*len(t))+1]
sns.distplot(recal_last_values[measure],kde=False,rug=True)
plt.title("distribution of last values "+measure)
plt.savefig('dropped '+measure)
plt.clf()
'''
method which create for every property many models based on parameters nu, gama and kernel
'''
def create_multiple_candidate_models(self):
measures=return_meas_per_prop()
change_folder("Training")
with open("start_data_coefs.json",'r')as handle:
first_values=json.load(handle)
with open("start_data_end_values.json",'r')as handle:
last_values=json.load(handle)
with open("start_data_coefs.json",'r')as handle:
aver_coefs=json.load(handle)
for property in measures:
count=0
for measure in measures[property]:
count+=1
I=np.array([[first_values[property][measure][j],last_values[property][measure][j],aver_coefs[property][measure][j]] for j in range(0,len(first_values[property][measure]))])
if count==1:
I2=I
else:
I2=np.concatenate((I2,I),axis=1)
change_inside_folder(property)
change_inside_folder("poly") #we can change the kernel to rbf and linear
nu_tes=0
gama=0
for a in range(1,21):
nu_tes=(a*0.01)
for b in range(1,21):
gama=(b*0.01)
#kernel can change to linear and rbf
clf = OneClassSVM(kernel="poly",nu=nu_tes,gamma=gama)
clf.fit(I2)
joblib.dump(clf,'nu_'+str(nu_tes)+'gama_'+str(gama)+'_'+property+'_model.joblib')
gama=0
move_initial_folder()
change_folder("Training")
change_inside_folder('models')
#method which create a model for every property based on the best combination of nu,gama and kernel according to percentage of prediction
def create_final_models(self):
measures=return_meas_per_prop()
change_folder("Training")
with open("start_data_coefs.json",'r')as handle:
first_values=json.load(handle)
with open("start_data_end_values.json",'r')as handle:
last_values=json.load(handle)
with open("start_data_coefs.json",'r')as handle:
aver_coefs=json.load(handle)
propert_attr={}
propert_attr['cohesion']=[0.01,0.01]
propert_attr['complexity']=[0.01,0.01]
propert_attr['documentation']=[0.01,0.01]
propert_attr['size']=[0.01,0.01]
propert_attr['coupling']=[0.01,0.01]
propert_attr['inheritance']=[0.01,0.01]
for property in measures:
count=0
for measure in measures[property]:
count+=1
I=np.array([[first_values[property][measure][j],last_values[property][measure][j],aver_coefs[property][measure][j]] for j in range(0,len(first_values[property][measure]))])
if count==1:
I2=I
else:
I2=np.concatenate((I2,I),axis=1)
nu_tes=propert_attr[property][0]
gama=propert_attr[property][1]
clf = OneClassSVM(kernel="poly",nu=nu_tes,gamma=gama)
clf.fit(I2)
joblib.dump(clf,'nu_'+str(nu_tes)+'gama_'+str(gama)+'_'+property+'_model.joblib')
'''
method which creates three json for target dropped data
first json contains for all measues the start values of target data
second json contains for all measures last values of target data
third json contains for all measures aver coefs of target data
'''
def create_dropped_target_data(self):
measures=return_meas_per_prop()
project='hibernate_hibernate-orm'
change_folder("Results_Classes_"+project)
with open("dropped_classes_start_stop.json",'r')as handle:
limits=json.load(handle)
with open("recalc_dropped_data.json",'r')as handle:
recalc_data=json.load(handle)
with open("final_coefs_dropped.json",'r')as handle:
final_coefs=json.load(handle)
start_values_data={}
end_values_data={}
coefs_data={}
for clas in recalc_data:
end_timeline=limits[clas][2]
start_timeline=limits[clas][0]
for property in measures:
if property not in start_values_data:
start_values_data[property]={}
end_values_data[property]={}
coefs_data[property]={}
for measure in measures[property]:
if measure not in start_values_data[property]:
start_values_data[property][measure]=[]
end_values_data[property][measure]=[]
coefs_data[property][measure]=[]
first_value=recalc_data[clas][start_timeline]["Metrics "+measure][0]
last_value=recalc_data[clas][end_timeline]["Metrics "+measure][-1]
coef=final_coefs[clas][measure]
start_values_data[property][measure].append(first_value)
end_values_data[property][measure].append(last_value)
coefs_data[property][measure].append(coef)
move_initial_folder()
change_folder("Training")
with open("end_dropped_data_first_values.json","w")as outfile:
json.dump(start_values_data,outfile)
with open("end_dropped_data_last_values.json","w")as outfile:
json.dump(end_values_data,outfile)
with open("end_dropped_data_coefs.json","w")as outfile:
json.dump(coefs_data,outfile)
'''
method which creates three json for target non dropped data
first json contains for all measues the start values of target data
second json contains for all measures last values of target data
third json contains for all measures aver coefs of target data
'''
def create_non_dropped_target_data(self):
measures=return_meas_per_prop()
project='hibernate_hibernate-orm'
change_folder("Results_Classes_"+project)
with open("non_dropped_classes_start_stop.json",'r')as handle:
limits=json.load(handle)
with open("recalc_non_dropped_data.json",'r')as handle:
recalc_data=json.load(handle)
with open("final_coefs_non_dropped.json",'r')as handle:
final_coefs=json.load(handle)
start_values_data={}
end_values_data={}
coefs_data={}
for clas in recalc_data:
end_timeline=limits[clas][1]
start_timeline=limits[clas][0]
for property in measures:
if property not in start_values_data:
start_values_data[property]={}
end_values_data[property]={}
coefs_data[property]={}
for measure in measures[property]:
if measure not in start_values_data[property]:
start_values_data[property][measure]=[]
end_values_data[property][measure]=[]
coefs_data[property][measure]=[]
first_value=recalc_data[clas][start_timeline]["Metrics "+measure][0]
last_value=recalc_data[clas][end_timeline]["Metrics "+measure][-1]
coef=final_coefs[clas][measure]
start_values_data[property][measure].append(first_value)
end_values_data[property][measure].append(last_value)
coefs_data[property][measure].append(coef)
move_initial_folder()
change_folder("Training")
with open("end_non_dropped_data_first_values.json","w")as outfile:
json.dump(start_values_data,outfile)
with open("end_non_dropped_data_last_values.json","w")as outfile:
json.dump(end_values_data,outfile)
with open("end_non_dropped_data_coefs.json","w")as outfile:
json.dump(coefs_data,outfile)
'''
method which use dropped target data to all models of properties based on gama,nu and kernel
prints the percentage of predict for these models and keeps the higher predictions
'''
def print_prediction_multiple_models(self):
change_folder("Results_Merge_Data")
measures=return_meas_per_prop()
with open("end_dropped_data_first_values.json",'r')as handle:
first_values=json.load(handle)
with open("end_dropped_data_last_values.json",'r')as handle:
last_values=json.load(handle)
with open("end_dropped_data_coefs.json",'r')as handle:
aver_coefs=json.load(handle)
move_initial_folder()
change_folder("Training")
change_inside_folder("models")
for property in measures:
change_inside_folder(property)
change_inside_folder("poly") #It can be change to linear and rbf
count=0
for measure in measures[property]:
count+=1
I=np.array([[first_values[property][measure][j],last_values[property][measure][j],aver_coefs[property][measure][j]] for j in range(0,len(first_values[property][measure]))])
if count==1:
I2=I
else:
I2=np.concatenate((I2,I),axis=1)
max_per=0
max_a=0
max_b=0
count=0
vals=[[0 for c in range(20)]for t in range(20)]
label_col=[69/255,139/255,116/255]
colors=[[(245/255,245/255,220/255) for c in range(20)]for t in range(20)]
labely=[]
labelx=[]
nu_1=0
for k in range(1,21):
nu_1=0.01*k
labely.append(nu_1)
labelx.append(nu_1)
for a in range(1,21):
nu_tes=(a*0.01)
for b in range(1,21):
gama=(b*0.01)
clf=joblib.load('nu_'+str(nu_tes)+'gama_'+str(gama)+'_'+property+'_model.joblib')
predictions=clf.predict(I2)
decision=clf.decision_function(I2)
k=round(predictions.tolist().count(1)/len(predictions),3)
if k>max_per:
max_per=k
max_a=a
max_b=b
vals[a-1][b-1]=k
colors[max_a-1][max_b-1]=[0,0,238/255]
tab=plt.table(cellText=vals,
rowLabels=labelx,
colLabels=labely,
rowColours=[label_col]*20,
colColours=[label_col]*20,
cellColours=colors,
cellLoc='center',
loc='upper left'
)
plt.axis('off')
move_initial_folder()
change_folder("Training")
change_inside_folder("Best_models")
plt.savefig(property)
plt.clf()
move_initial_folder()
change_folder("Training")
change_inside_folder("models")
print('Max percentage '+str(max_per)+' for nu '+str(max_a*0.01)+' and for gama '+str(max_b*0.01)+" property "+property)
'''
method which create for every property csv files with all dropped classes
and first values,last values and final coefs of all measures inside property
'''
def create_csv_data_dropped(self,projects):
measures=return_meas_per_prop()
classes=[]
proj=[]
start_values_data={}
end_values_data={}
coefs_data={}
for project in projects:
change_folder("Results_Classes_"+project)
with open("recalc_dropped_data.json",'r')as handle:
recalc_data=json.load(handle)
with open("final_coefs_dropped.json",'r')as handle:
final_coefs=json.load(handle)
with open("dropped_classes_start_stop.json",'r')as handle:
limits=json.load(handle)
with open("anomalies.json",'r')as handle:
anomalies=json.load(handle)
with open("filter_classes.json",'r')as handle:
filter=json.load(handle)
with open("short_life_classes.json",'r')as handle:
short_life=json.load(handle)
for clas in recalc_data:
#if clas not in short_life and clas in filter and clas not in anomalies:
end_timeline=limits[clas][2]
start_timeline=limits[clas][0]
classes.append(clas)
proj.append(project)
for property in measures:
if property not in start_values_data:
start_values_data[property]={}
end_values_data[property]={}
coefs_data[property]={}
for measure in measures[property]:
if measure not in start_values_data[property]:
start_values_data[property][measure]=[]
end_values_data[property][measure]=[]
coefs_data[property][measure]=[]
first_value=recalc_data[clas][start_timeline]['Metrics '+measure][0]
last_value=recalc_data[clas][end_timeline]["Metrics "+measure][-1]
coef=round(final_coefs[clas][measure],4)
start_values_data[property][measure].append(first_value)
end_values_data[property][measure].append(last_value)
coefs_data[property][measure].append(coef)
move_initial_folder()
change_inside_folder("Csvs_files_dropped")
for property in measures:
data=OrderedDict()
data['classes']=classes
data['project']=proj
for measure in measures[property]:
data['Start values '+measure]=start_values_data[property][measure]
data['Last values '+measure]=end_values_data[property][measure]
data['Coefs '+measure]=coefs_data[property][measure]
ind=[]
for a in range(0,len(classes)):
ind.append(a+1)
df=pd.DataFrame(data,index=ind)
df.to_csv(property+".csv",encoding='utf-8')
'''
method which creates for every property csv files with all non dropped classes
first values,last values and final coefs of all measures inside property
'''
def create_csv_data_non_dropped(self,projects):
measures=return_meas_per_prop()
classes=[]
proj=[]
start_values_data={}
end_values_data={}
coefs_data={}
for project in projects:
change_folder("Results_Classes_"+project)
with open("recalc_non_dropped_data.json",'r')as handle:
recalc_data=json.load(handle)
with open("final_coefs_non_dropped.json",'r')as handle:
final_coefs=json.load(handle)
with open("non_dropped_classes_start_stop.json",'r')as handle:
limits=json.load(handle)
with open("anomalies.json",'r')as handle:
anomalies=json.load(handle)
with open("filter_classes.json",'r')as handle:
filter=json.load(handle)
with open("short_life_classes.json",'r')as handle:
short_life=json.load(handle)
for clas in recalc_data:
#if clas not in short_life and clas in filter and clas not in anomalies:
end_timeline=limits[clas][1]
start_timeline=limits[clas][0]
classes.append(clas)
proj.append(project)
for property in measures:
if property not in start_values_data:
start_values_data[property]={}
end_values_data[property]={}
coefs_data[property]={}
for measure in measures[property]:
if measure not in start_values_data[property]:
start_values_data[property][measure]=[]
end_values_data[property][measure]=[]
coefs_data[property][measure]=[]
first_value=recalc_data[clas][start_timeline]['Metrics '+measure][0]
last_value=recalc_data[clas][end_timeline]["Metrics "+measure][-1]
coef=round(final_coefs[clas][measure],4)
start_values_data[property][measure].append(first_value)
end_values_data[property][measure].append(last_value)
coefs_data[property][measure].append(coef)
move_initial_folder()
change_inside_folder("Csvs_files_non_dropped")
for property in measures:
data=OrderedDict()
data['classes']=classes
data['project']=proj
for measure in measures[property]:
data['Start values '+measure]=start_values_data[property][measure]
data['Last values '+measure]=end_values_data[property][measure]
data['Coefs '+measure]=coefs_data[property][measure]
ind=[]
for a in range(0,len(classes)):
ind.append(a+1)
df=pd.DataFrame(data,index=ind)
df.to_csv(property+".csv",encoding='utf-8')
'''
method which create for every property distributions of scores of target non dropped classes
it also creates a csv files with all non dropped target classes, their first values ,last values
,final coefs of all measures, their scores for all properties and the final average scores of the
prediction
'''
def create_distribution_scores_non_dropped(self):
measures=return_meas_per_prop()
change_folder("Training")
with open("end_non_dropped_data_first_values.json",'r')as handle:
first_values=json.load(handle)
with open("end_non_dropped_data_last_values.json",'r')as handle:
last_values=json.load(handle)
with open("end_non_dropped_data_coefs.json",'r')as handle:
aver_coefs=json.load(handle)
propert_attr={}
propert_attr['cohesion']=[0.01,0.01]
propert_attr['complexity']=[0.01,0.01]
propert_attr['documentation']=[0.01,0.01]
propert_attr['size']=[0.01,0.01]
propert_attr['coupling']=[0.01,0.01]
propert_attr['inheritance']=[0.01,0.01]
non_dropped_scores=OrderedDict()
for property in measures:
count1=0
start=time.time()
for measure in measures[property]:
non_dropped_scores['Start_values '+measure]=first_values[property][measure]
non_dropped_scores['Last values '+measure]=last_values[property][measure]
non_dropped_scores['Coefs '+measure]=aver_coefs[property][measure]
count1+=1
I=np.array([[first_values[property][measure][j],last_values[property][measure][j],aver_coefs[property][measure][j]] for j in range(0,len(first_values[property][measure]))])
if count1==1:
I2=I
else:
I2=np.concatenate((I2,I),axis=1)
end=time.time()
nu_tes=propert_attr[property][0]
gama=propert_attr[property][1]
clf=joblib.load('nu_'+str(nu_tes)+'gama_'+str(gama)+'_'+property+'_model.joblib')
predictions=clf.predict(I2)
decision=clf.decision_function(I2)
decis=[]
for val in decision:
decis.append(val[0])
sort_dec=[]
for val in decis:
sort_dec.append(val)
sort_dec.sort()
min_lim=sort_dec[int(0.05*len(sort_dec))+1]
max_lim=sort_dec[int(0.95*len(sort_dec))+1]
A=[]
for val in decis:
if val>0:
if val<max_lim:
b=0.5+(val/max_lim)*0.5
if property=="cohesion":
b-=0.01
else:
b=1
if b>1:
b=1
if property =='documentation':
A.append(1-b)
else:
A.append(b)
elif val<0:
if val>min_lim:
b=0.5-(val/min_lim)*0.5
else:
b=0
if property =='documentation':
A.append(1-b)
else:
A.append(b)
else:
if property=="documentation":
A.append(0.5)
else:
A.append(0.5)
non_dropped_scores['Score of '+property]=A
plt.hist(A,weights=np.ones(len(A))/len(A),bins=30)#move_initial_folder()
plt.ylim(0,1.0)
plt.savefig(property+"_non_dropped.png")
plt.clf()
average_score=[]
for count in range(0,len(A)):
aver=0
for property in measures:
val=non_dropped_scores['Score of '+property][count]
aver+=val
average_score.append(aver/len(measures))
non_dropped_scores['Average_score']=average_score
pos_score=[]
for count in range(0,len(A)):
posit=0
for property in measures:
val=non_dropped_scores['Score of '+property][count]
if val>0.5:
posit+=val
pos_score.append(posit)
non_dropped_scores["Positive_score"]=pos_score
df=pd.DataFrame(non_dropped_scores)
df.to_csv("non_dropped_scores.csv",encoding='utf-8',index=False)
'''
method which create for every property distributions of scores of target dropped classes
it also creates a csv files with all dropped target classes, their first values ,last values
,final coefs of all measures, their scores for all properties and the final average scores of the
prediction
'''
def create_distribution_scores_dropped(self):
measures=return_meas_per_prop()
change_folder("Training")
with open("end_dropped_data_first_values.json",'r')as handle:
first_values=json.load(handle)
with open("end_dropped_data_last_values.json",'r')as handle:
last_values=json.load(handle)
with open("end_dropped_data_coefs.json",'r')as handle:
aver_coefs=json.load(handle)
propert_attr={}
propert_attr['cohesion']=[0.01,0.01]
propert_attr['complexity']=[0.01,0.01]
propert_attr['documentation']=[0.01,0.01]
propert_attr['size']=[0.01,0.01]
propert_attr['coupling']=[0.01,0.01]
propert_attr['inheritance']=[0.01,0.01]
dropped_scores=OrderedDict()
for property in measures:
count1=0
for measure in measures[property]:
dropped_scores['Start_values '+measure]=first_values[property][measure]
dropped_scores['Last values '+measure]=last_values[property][measure]
dropped_scores['Coefs '+measure]=aver_coefs[property][measure]
count1+=1
I=np.array([[first_values[property][measure][j],last_values[property][measure][j],aver_coefs[property][measure][j]] for j in range(0,len(first_values[property][measure]))])
if count1==1: