Skip to content

Commit

Permalink
remove last file after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
fa1c4 committed Jan 3, 2022
1 parent ada0df3 commit 20c0140
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 229 deletions.
35 changes: 5 additions & 30 deletions results/1_10_fraction_retrain_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.7917981072555205,0.5968606472015381
1,0.7913866410643259,1.492163896560669
2,0.7911123302701961,2.313441276550293
3,0.790152242490742,3.5358822345733643
4,0.7894664655054177,4.624298810958862
5,0.789054999314223,5.555612802505493
6,0.7893293101083527,6.441725492477417
7,0.7891921547112879,7.237414121627808
8,0.7900150870936772,7.994604587554932
9,0.7891921547112879,8.738701343536377
10,0.7893293101083527,9.42024278640747
11,0.7887806885200933,10.210513353347778
12,0.7887806885200933,10.857799291610718
13,0.7886435331230284,11.536596059799194
14,0.7875462899465094,12.223093509674072
15,0.786860512961185,12.898322582244873
16,0.7869976683582499,13.568557262420654
17,0.7863118913729256,14.259593963623047
18,0.7861747359758606,14.833626985549927
19,0.7863118913729256,15.40062165260315
20,0.7861747359758606,16.014375925064087
21,0.7859004251817309,16.656851768493652
22,0.7854889589905363,17.292553186416626
23,0.7843917158140172,17.955029726028442
24,0.7843917158140172,18.59359383583069
25,0.7827458510492388,19.34312343597412
26,0.7830201618433685,19.972756385803223
27,0.7823343848580442,20.579628229141235
28,0.782471540255109,21.19595170021057
29,0.7828830064463037,21.754724979400635
0,0.7905637086819366,0.4226658344268799
1,0.7908380194760664,1.123835563659668
2,0.7896036209024825,1.758284330368042
3,0.790152242490742,2.376178741455078
4,0.7908380194760664,2.973546266555786
35 changes: 5 additions & 30 deletions results/1_15_fraction_retrain_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.7761623919901248,0.6061851978302002
1,0.7758880811959951,1.3753862380981445
2,0.7762995473871896,1.8982110023498535
3,0.7760252365930599,2.446392297744751
4,0.7756137704018653,2.9644880294799805
5,0.7762995473871896,3.443305015563965
6,0.7758880811959951,4.151177644729614
7,0.7762995473871896,5.0940022468566895
8,0.7762995473871896,6.27827525138855
9,0.7756137704018653,7.280501365661621
10,0.7754766150048005,8.042450904846191
11,0.7746536826224112,8.541795015335083
12,0.7738307502400219,8.994153261184692
13,0.7735564394458921,9.514929294586182
14,0.7732821286517625,10.034508228302002
15,0.772733507063503,10.539336442947388
16,0.7721848854752434,11.148948669433594
17,0.7709504869016596,11.707820177078247
18,0.7716362638869839,12.151366233825684
19,0.7710876422987245,12.578791618347168
20,0.7720477300781786,13.05399203300476
21,0.7717734192840489,13.489069700241089
22,0.7709504869016596,13.999388933181763
23,0.7699903991222055,14.516704797744751
24,0.7713619530928542,14.988868951797485
25,0.7710876422987245,15.51879358291626
26,0.7709504869016596,16.006236791610718
27,0.7709504869016596,16.543922901153564
28,0.7708133315045947,17.11853051185608
29,0.770539020710465,17.55792784690857
0,0.7757509257989302,0.3392763137817383
1,0.7757509257989302,0.7557206153869629
2,0.7760252365930599,1.2300143241882324
3,0.7756137704018653,1.663421869277954
4,0.7760252365930599,2.1615872383117676
35 changes: 5 additions & 30 deletions results/1_5_fraction_retrain_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.8138801261829653,0.8139553070068359
1,0.8140172815800302,2.0597801208496094
2,0.8140172815800302,3.2409777641296387
3,0.814154436977095,4.287345886230469
4,0.8138801261829653,5.769192218780518
5,0.8137429707859004,7.035276651382446
6,0.8133315045947058,8.203376054763794
7,0.8129200384035111,9.42108964920044
8,0.812097106021122,10.634456872940063
9,0.812097106021122,11.921549797058105
10,0.811959950624057,13.060882091522217
11,0.812097106021122,14.205500364303589
12,0.8114113290357976,15.408828020095825
13,0.8109998628446029,16.755947828292847
14,0.8107255520504731,17.76923155784607
15,0.8112741736387327,18.93325114250183
16,0.8115484844328624,20.157156467437744
17,0.8114113290357976,21.263965129852295
18,0.811959950624057,22.489388942718506
19,0.8111370182416678,23.638585329055786
20,0.812097106021122,24.870457410812378
21,0.8114113290357976,25.924683570861816
22,0.8108627074475381,27.062446117401123
23,0.8112741736387327,28.360248565673828
24,0.8111370182416678,29.612057209014893
25,0.8109998628446029,30.784350156784058
26,0.8103140858592786,32.129491090774536
27,0.8108627074475381,33.685486793518066
28,0.8104512412563435,34.84719896316528
29,0.8103140858592786,35.942861795425415
0,0.8134686599917706,0.7565746307373047
1,0.8133315045947058,1.9375522136688232
2,0.8138801261829653,3.00258207321167
3,0.8136058153888356,4.032928705215454
4,0.8126457276093815,5.04685378074646
35 changes: 5 additions & 30 deletions results/fullretrain_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.8948018104512413,3.153808832168579
1,0.8942531888629818,8.047770500183105
2,0.8941160334659168,13.15370488166809
3,0.8941160334659168,18.238775491714478
4,0.8943903442600466,23.903899669647217
5,0.8946646550541764,29.161866426467896
6,0.8946646550541764,34.56741642951965
7,0.893978878068852,39.76766085624695
8,0.8948018104512413,44.90149736404419
9,0.8950761212453711,50.2125461101532
10,0.8946646550541764,55.36747717857361
11,0.8950761212453711,60.54462742805481
12,0.8954875874365656,65.36863350868225
13,0.8949389658483061,70.5425980091095
14,0.8946646550541764,75.46760416030884
15,0.8943903442600466,80.56883215904236
16,0.8937045672747223,85.88708853721619
17,0.8934302564805925,90.91791129112244
18,0.8927444794952681,95.90959644317627
19,0.8927444794952681,100.96271085739136
20,0.8923330133040736,106.17920732498169
21,0.8924701687011384,111.32231950759888
22,0.892881634892333,116.37431216239929
23,0.892881634892333,121.65272212028503
24,0.8926073240982033,126.83410930633545
25,0.8924701687011384,132.2915494441986
26,0.8923330133040736,137.9828565120697
27,0.8926073240982033,142.94215846061707
28,0.8920587025099438,148.37671399116516
29,0.8923330133040736,153.94352960586548
0,0.8950761212453711,3.1790289878845215
1,0.8948018104512413,8.141436576843262
2,0.8943903442600466,12.757618188858032
3,0.8953504320395007,17.17648935317993
4,0.8950761212453711,21.688454389572144
35 changes: 5 additions & 30 deletions results/shards10_unlearning_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.8090258668134287,2.2001426219940186
1,0.8090258668134287,2.6331143379211426
2,0.8090258668134287,3.018749237060547
3,0.8090258668134287,3.484102725982666
4,0.8088882773802972,3.9745006561279297
5,0.8088882773802972,4.306251764297485
6,0.8091634562465603,4.689649343490601
7,0.8091634562465603,5.156806707382202
8,0.8090258668134287,5.631770849227905
9,0.8093010456796919,5.97024393081665
10,0.8091634562465603,6.455369710922241
11,0.8091634562465603,6.812710762023926
12,0.8091634562465603,7.247638940811157
13,0.8093010456796919,7.7624828815460205
14,0.8093010456796919,8.321550130844116
15,0.8090258668134287,8.807941198348999
16,0.8090258668134287,9.404858112335205
17,0.8090258668134287,9.820172786712646
18,0.8090258668134287,10.349631786346436
19,0.8090258668134287,10.846659660339355
20,0.8090258668134287,11.30949330329895
21,0.8090258668134287,11.767237424850464
22,0.8093010456796919,12.255142211914062
23,0.8091634562465603,12.742095708847046
24,0.8086130985140341,13.260343551635742
25,0.8090258668134287,13.772712230682373
26,0.8090258668134287,14.269036293029785
27,0.8091634562465603,14.751636981964111
28,0.8091634562465603,15.272844791412354
29,0.8091634562465603,15.651252269744873
0,0.8090258668134287,2.012634515762329
1,0.8090258668134287,2.316821813583374
2,0.8090258668134287,2.7696096897125244
3,0.8090258668134287,3.1795125007629395
4,0.8090258668134287,3.5385525226593018
35 changes: 5 additions & 30 deletions results/shards15_unlearning_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.7963676389653275,2.5766398906707764
1,0.7963676389653275,2.925642728805542
2,0.7963676389653275,3.2963685989379883
3,0.7963676389653275,3.575709104537964
4,0.7963676389653275,3.900413751602173
5,0.7960924600990644,4.219345331192017
6,0.7960924600990644,4.55573034286499
7,0.7960924600990644,4.827460050582886
8,0.7960924600990644,5.1063268184661865
9,0.7960924600990644,5.443089246749878
10,0.7960924600990644,5.785690069198608
11,0.7960924600990644,6.0828893184661865
12,0.7960924600990644,6.358281850814819
13,0.7960924600990644,6.632842063903809
14,0.7960924600990644,6.910656213760376
15,0.7956796917996698,7.228364706039429
16,0.7956796917996698,7.605190753936768
17,0.7956796917996698,7.918082237243652
18,0.7956796917996698,8.197046995162964
19,0.7956796917996698,8.51812481880188
20,0.7956796917996698,8.828375816345215
21,0.7956796917996698,9.14735460281372
22,0.7956796917996698,9.429996013641357
23,0.7955421023665382,9.747061252593994
24,0.7955421023665382,10.081171989440918
25,0.7955421023665382,10.455705404281616
26,0.7955421023665382,10.829243421554565
27,0.7955421023665382,11.117472648620605
28,0.7955421023665382,11.514079570770264
29,0.7955421023665382,11.86928677558899
0,0.7963676389653275,2.398097038269043
1,0.7963676389653275,2.743192434310913
2,0.796505228398459,3.0413970947265625
3,0.796505228398459,3.347128391265869
4,0.796505228398459,3.6309216022491455
35 changes: 5 additions & 30 deletions results/shards5_unlearning_res.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
,accuracys,unlearning time
0,0.8241607044578977,2.3396260738372803
1,0.8242982938910292,3.370234489440918
2,0.8244358833241607,4.0333452224731445
3,0.8242982938910292,4.769611120223999
4,0.8241607044578977,5.410383224487305
5,0.8240231150247661,6.118927717208862
6,0.8240231150247661,6.895174503326416
7,0.8238855255916345,7.570781946182251
8,0.8237479361585031,8.156978607177734
9,0.8233351678591084,8.943801403045654
10,0.8236103467253715,9.58351993560791
11,0.82347275729224,10.199347734451294
12,0.8237479361585031,10.879125833511353
13,0.8237479361585031,11.650331258773804
14,0.8240231150247661,12.463914155960083
15,0.8241607044578977,13.124300718307495
16,0.8241607044578977,13.843977928161621
17,0.8242982938910292,14.789794445037842
18,0.8244358833241607,15.582483530044556
19,0.8244358833241607,16.335221529006958
20,0.8247110621904238,16.953579425811768
21,0.8247110621904238,17.663076400756836
22,0.8249862410566868,18.315706968307495
23,0.8249862410566868,18.94924807548523
24,0.8251238304898184,19.57866358757019
25,0.8249862410566868,20.244060516357422
26,0.8248486516235554,20.938979625701904
27,0.8252614199229499,21.571834325790405
28,0.8252614199229499,22.25372838973999
29,0.8252614199229499,23.12247395515442
0,0.8241607044578977,1.821343183517456
1,0.8241607044578977,2.3584578037261963
2,0.8241607044578977,3.0576889514923096
3,0.8240231150247661,3.7224462032318115
4,0.8241607044578977,4.318850755691528
3 changes: 3 additions & 0 deletions score/KNN/Cls_Fullretrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib.pyplot as plt
from Kbatch_KNNunlearning import KNNbase_Unlearning
from KnnPred import knnpred
import os


class Fullretrain():
Expand Down Expand Up @@ -33,6 +34,8 @@ def unlearning(self):
acc_temp, _ = Pred.calculate_accuracy()
accuracys.append(acc_temp)

last_file_path = "../../data/u-unlearning{}.csv".format(next_index)
os.remove(last_file_path)
res = {'accuracys': accuracys, 'unlearning time': unlearning_times}
res_data = pd.DataFrame(res)
res_data.to_csv('../../results/fullretrain_res.csv')
Expand Down
9 changes: 7 additions & 2 deletions score/KNN/Cls_Knnbagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from bagging_KNNunlearning import KNNbase_Unlearning
from KnnPred import knnpred
import random

import os

class Knnbagging():

Expand Down Expand Up @@ -50,6 +50,7 @@ def unlearning(self):
models[s].data_readin('../../data/shards_{}_{}/dataset_sharded{}.csv'.format(self.shards, self.shuffled_ordered_str, s))
models[s].data_df.to_csv("../../data/shards_{}_{}/shard{}-unlearning0.csv".format(self.shards, self.shuffled_ordered_str, s),
sep="\t", header=None, index=False)

accuracys, unlearning_times, next_indexs = [], [], []
time_start = time.time()
for s in range(self.shards):
Expand All @@ -69,6 +70,10 @@ def unlearning(self):
print('shards {}\'s accuracy: {}'.format(self.shards, acc_temp))
bagging_time += time.time() - bagging_start

for s in range(self.shards):
last_file_path = os.path.expanduser("../../data/shards_{}_{}/shard{}-unlearning{}.csv".format(self.shards, self.shuffled_ordered_str, s, next_indexs[s]))
os.remove(last_file_path)

res = {'accuracys': accuracys, 'unlearning time': unlearning_times}
res_data = pd.DataFrame(res)
res_data.to_csv('../../results/shards{}_unlearning_res.csv'.format(self.shards))
Expand Down Expand Up @@ -103,7 +108,7 @@ def unlearning(self):


if __name__ == '__main__':
test_knnbagging = Knnbagging(10, True, 50, 5)
test_knnbagging = Knnbagging(10, True, 50, 3)
test_knnbagging.unlearning()
res = pd.read_csv('../../results/shards{}_unlearning_res.csv'.format(test_knnbagging.shards))
accuracys = res['accuracys']
Expand Down
5 changes: 4 additions & 1 deletion score/KNN/Cls_Sfraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib.pyplot as plt
from Kbatch_KNNunlearning import KNNbase_Unlearning
from KnnPred import knnpred
import os


class S_fraction():
Expand Down Expand Up @@ -37,13 +38,15 @@ def unlearning(self):
accuracys.append(acc_temp)
print('accuracy: {}'.format(acc_temp))

last_file_path = os.path.expanduser('../../data/shards_{}_{}/u-unlearning{}.csv'.format(self.shards, self.shuffled_ordered_str, next_index))
os.remove(last_file_path)
res = {'accuracys': accuracys, 'unlearning time': unlearning_times}
res_data = pd.DataFrame(res)
res_data.to_csv('../../results/1_{}_fraction_retrain_res.csv'.format(self.shards))


if __name__ == '__main__':
test_s_fraction = S_fraction(10, True, 50, 5)
test_s_fraction = S_fraction(10, True, 50, 3)
test_s_fraction.unlearning()
res = pd.read_csv('../../results/1_{}_fraction_retrain_res.csv'.format(test_s_fraction.shards))
accuracys = res['accuracys']
Expand Down
14 changes: 5 additions & 9 deletions score/KNN/Kbatch_KNNunlearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ def __init__(self, shuffle=False, shards=1, remove_files_flag=True):
self.alg, self.user_ids = None, None
self.shuffle, self.shards = shuffle, shards
self.remove_files_flag, self.original_flag = remove_files_flag, True
self.file_path = None

def data_readin(self, path_to_udata):
file_path = os.path.expanduser(path_to_udata)
self.file_path = os.path.expanduser(path_to_udata)
# print(file_path)
# 使用Reader指定文本格式,参数line_format指定特征(列名),参数sep指定分隔符
self.reader = Reader(line_format='user item rating timestamp', sep='\t')
# 加载数据集
self.data = Dataset.load_from_file(file_path, reader=self.reader)
self.data_df = pd.read_csv(file_path, sep='\t', header=None, names=['user', 'item', 'rating', 'timestamp'])
self.data = Dataset.load_from_file(self.file_path, reader=self.reader)
self.data_df = pd.read_csv(self.file_path, sep='\t', header=None, names=['user', 'item', 'rating', 'timestamp'])

if self.remove_files_flag and self.original_flag == False:
os.remove(file_path)
os.remove(self.file_path)
self.original_flag = False

# sorted data dataframe as user id and timestamp
Expand Down Expand Up @@ -156,17 +157,12 @@ def recommendation_unlearning(self, forgetting_index, batchsize):
for _ in range(batchsize):
uid = random.choice(self.user_ids).item()
uids.append(uid)
# print("----- select user uids -----")
# print(uids)

history_index = []
for _ in range(batchsize):
data_user = self.getting_user_history(uids[_])
indexarr = data_user.index.values
history_index_temp = random.choice(indexarr).item()
# dest = data_user.loc[history_index_temp]
# movie_name = dest["item"]
# movie_index = self.movie_name_to_item(movie_name)
history_index.append(history_index_temp)

self.unlearning_request(history_index)
Expand Down
Binary file modified score/KNN/__pycache__/Cls_Fullretrain.cpython-39.pyc
Binary file not shown.
Binary file modified score/KNN/__pycache__/Cls_Knnbagging.cpython-39.pyc
Binary file not shown.
Binary file modified score/KNN/__pycache__/Cls_Sfraction.cpython-39.pyc
Binary file not shown.
Binary file modified score/KNN/__pycache__/Kbatch_KNNunlearning.cpython-39.pyc
Binary file not shown.
Binary file modified score/KNN/__pycache__/bagging_KNNunlearning.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit 20c0140

Please sign in to comment.