Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions semisupervised/DensityPeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sklearn.svm import SVC

from instance_selection import ENN

from .utils import split


Expand All @@ -31,19 +32,19 @@ class STDPNF:
"""

def __init__(
self,
dc=None,
distance_metric="euclidean",
k=3,
gauss_cutoff=True,
percent=2.0,
density_threshold=None,
distance_threshold=None,
anormal=True,
filtering=False,
classifier=None,
classifier_params=None,
filter_method=None,
self,
dc=None,
distance_metric="euclidean",
k=3,
gauss_cutoff=True,
percent=2.0,
density_threshold=None,
distance_threshold=None,
anormal=True,
filtering=False,
classifier=None,
classifier_params=None,
filter_method=None,
):
"""Semi Supervised Algorithm based on Density Peaks."""
self.dc = dc
Expand Down Expand Up @@ -121,8 +122,7 @@ def __auto_select_dc(self):

while True:
nneighs = (
sum([1 for v in self.distances.values() if
v < dc]) / self.n_id ** 2
sum([1 for v in self.distances.values() if v < dc]) / self.n_id**2
)
if 0.01 <= nneighs <= 0.02:
break
Expand Down Expand Up @@ -476,7 +476,7 @@ def _fit_stdpnf(self):
while count <= max(self.order.values()):
unlabeled_rows = self.structure_stdnpf.loc[
self.structure_stdnpf["label"] == -1
].index.to_list()
].index.to_list()
unlabeled_indexes = []
for row in unlabeled_rows:
if self.order[row] == count:
Expand All @@ -492,7 +492,7 @@ def _fit_stdpnf(self):
else:
labeled_data = self.structure_stdnpf.loc[
self.structure_stdnpf["label"] != -1
]
]
complete = labeled_data["sample"]
complete_y = labeled_data["label"]

Expand All @@ -502,15 +502,14 @@ def _fit_stdpnf(self):

labeled_data = self.structure_stdnpf.loc[
self.structure_stdnpf["label"] != -1
]
]
self.classifier_stdpnf.fit(
labeled_data["sample"].tolist(), labeled_data["label"].tolist()
)

count += 1

labeled_data = self.structure_stdnpf.loc[
self.structure_stdnpf["label"] != -1]
labeled_data = self.structure_stdnpf.loc[self.structure_stdnpf["label"] != -1]
self.classifier_stdpnf.fit(
labeled_data["sample"].tolist(), labeled_data["label"].tolist()
)
Expand All @@ -533,8 +532,7 @@ def _results_to_structure(self, complete, result):
if not is_in:
results_to_unlabeled.append(r)
for r in results_to_unlabeled:
self.structure_stdnpf.at[
np.array(self.structure_stdnpf["sample"], r)][
self.structure_stdnpf.at[np.array(self.structure_stdnpf["sample"], r)][
"label"
] = -1

Expand Down