1616from sklearn .svm import SVC
1717
1818from instance_selection import ENN
19-
2019from .utils import split
2120
2221
@@ -32,19 +31,19 @@ class STDPNF:
3231 """
3332
3433 def __init__ (
35- self ,
36- dc = None ,
37- distance_metric = "euclidean" ,
38- k = 3 ,
39- gauss_cutoff = True ,
40- percent = 2.0 ,
41- density_threshold = None ,
42- distance_threshold = None ,
43- anormal = True ,
44- filtering = False ,
45- classifier = None ,
46- classifier_params = None ,
47- filter_method = None ,
34+ self ,
35+ dc = None ,
36+ distance_metric = "euclidean" ,
37+ k = 3 ,
38+ gauss_cutoff = True ,
39+ percent = 2.0 ,
40+ density_threshold = None ,
41+ distance_threshold = None ,
42+ anormal = True ,
43+ filtering = False ,
44+ classifier = None ,
45+ classifier_params = None ,
46+ filter_method = None ,
4847 ):
4948 """Semi Supervised Algorithm based on Density Peaks."""
5049 self .dc = dc
@@ -70,6 +69,22 @@ def __init__(
7069 else :
7170 self .filter = None
7271
72+ self .y = None
73+ self .l = None
74+ self .u = None
75+ self .classifier_stdpnf = None
76+ self .order = None
77+ self .structure = None
78+ self .structure_stdnpf = None
79+ self .n_id = None
80+ self .distances = None
81+ self .max_dis = None
82+ self .min_dis = None
83+ self .rho = None
84+ self .delta = None
85+ self .nneigh = None
86+ self .data = None
87+
7388 def __build_distance (self ):
7489 """
7590 Calculate distance dict.
@@ -106,7 +121,8 @@ def __auto_select_dc(self):
106121
107122 while True :
108123 nneighs = (
109- sum ([1 for v in self .distances .values () if v < dc ]) / self .n_id ** 2
124+ sum ([1 for v in self .distances .values () if
125+ v < dc ]) / self .n_id ** 2
110126 )
111127 if 0.01 <= nneighs <= 0.02 :
112128 break
@@ -460,7 +476,7 @@ def _fit_stdpnf(self):
460476 while count <= max (self .order .values ()):
461477 unlabeled_rows = self .structure_stdnpf .loc [
462478 self .structure_stdnpf ["label" ] == - 1
463- ].index .to_list ()
479+ ].index .to_list ()
464480 unlabeled_indexes = []
465481 for row in unlabeled_rows :
466482 if self .order [row ] == count :
@@ -476,7 +492,7 @@ def _fit_stdpnf(self):
476492 else :
477493 labeled_data = self .structure_stdnpf .loc [
478494 self .structure_stdnpf ["label" ] != - 1
479- ]
495+ ]
480496 complete = labeled_data ["sample" ]
481497 complete_y = labeled_data ["label" ]
482498
@@ -486,14 +502,15 @@ def _fit_stdpnf(self):
486502
487503 labeled_data = self .structure_stdnpf .loc [
488504 self .structure_stdnpf ["label" ] != - 1
489- ]
505+ ]
490506 self .classifier_stdpnf .fit (
491507 labeled_data ["sample" ].tolist (), labeled_data ["label" ].tolist ()
492508 )
493509
494510 count += 1
495511
496- labeled_data = self .structure_stdnpf .loc [self .structure_stdnpf ["label" ] != - 1 ]
512+ labeled_data = self .structure_stdnpf .loc [
513+ self .structure_stdnpf ["label" ] != - 1 ]
497514 self .classifier_stdpnf .fit (
498515 labeled_data ["sample" ].tolist (), labeled_data ["label" ].tolist ()
499516 )
@@ -516,7 +533,8 @@ def _results_to_structure(self, complete, result):
516533 if not is_in :
517534 results_to_unlabeled .append (r )
518535 for r in results_to_unlabeled :
519- self .structure_stdnpf .at [np .array (self .structure_stdnpf ["sample" ], r )][
536+ self .structure_stdnpf .at [
537+ np .array (self .structure_stdnpf ["sample" ], r )][
520538 "label"
521539 ] = - 1
522540
0 commit comments