sbn_path_index, ac_dist, cof_ = [], [], []
for i in range(X.shape[0]):
sbn_path = sorted(range(len(dist_matrix.loc[i].tolist())),
key=dist_matrix.loc[i].tolist().__getitem__)
sbn_path_index.append(sbn_path[1: self.n_neighbors_ + 1])
cost_desc = []
// this section takes the most time if number of neighbors is high!
After Change
:return: numpy array containing COF scores for observations.
The greater the COF, the greater the outlierness.
dist_matrix = np.array(distance_matrix(X, X))
sbn_path_index, ac_dist, cof_ = [], [], []
for i in range(X.shape[0]):
sbn_path = sorted(range(len(dist_matrix[i])),
key=dist_matrix[i].__getitem__)
sbn_path_index.append(sbn_path[1: self.n_neighbors_ + 1])
cost_desc = []
for j in range(self.n_neighbors_):
cost_desc.append(np.min(dist_matrix[sbn_path[j + 1]][sbn_path][:j + 1]))
acd = []
for _h, cost_ in enumerate(cost_desc):
acd.append(((2. * (self.n_neighbors_ + 1 - (_h + 1))) /