def score(self, trajectory, ground_truth, verbose=False, **kwargs): segment_id = self.core(trajectory, **kwargs) h = harmonic_mean(segments=segment_id, tsid=ground_truth[0], label=ground_truth[1]) if verbose: print( "Scoring " + ','.join('{0}={1!r}'.format(k, kwargs[k]) for k in kwargs), str(h)) return h
def get_best_eps(self, error_signal, train_data, ground_truth, verbose=False): ep_a = self.get_eps_candidates(error_signal) epsa = {} epsp = {} for _, ix_ in ep_a: segmet_id = self.sws_segmentation(dataframe=train_data, error_array=error_signal, ep=_, verbose=verbose) h = harmonic_mean(segments=segmet_id, tsid=ground_truth[0], label=ground_truth[1]) epsa[_] = h epsp[_] = ix_ epsa_a = None epsa_k = None epsa_p = None for k in epsa.keys(): if epsa_a is None: epsa_a = epsa[k] epsa_k = k epsa_p = epsp[k] else: if epsa_a <= epsa[k]: epsa_a = epsa[k] epsa_k = k epsa_p = epsp[k] if verbose: print('best eps:', epsa_a, ' for candidate : ', epsa_k, "p:", epsa_p) return epsa_a, epsa_k, epsa_p
except: print("error reading file") continue # try: adbscan.cluster_trajectory_point(tp) # print("current cluster:",adbscan.current_cluster) # except Exception as e: # print("error clustering:",e) from Trajlib2.SegmentationEvaluation import purity, coverage, harmonic_mean adbscan.all_eps() ground_truth = adbscan.get_segment_id() labels = adbscan.get_ground_truth() trans_mod = adbscan.get_ground_mode() segment_id = adbscan.get_segment_id() print(labels) print(trans_mod) print(segment_id) print(purity(ground_truth_label=trans_mod, generated_segment_id=segment_id)) print(coverage(ground_truth_segment_id=labels, generated_segment_id=segment_id)) print(harmonic_mean(segments=segment_id, tsid=labels, label=trans_mod)) from Trajlib2.core.traj_reconstruct import plot_df import pandas as pd from Trajlib2.databases import load_datasets ds = load_datasets.load_data_fishing_data( "/Users/owner/Trajlib2/Trajlib2/databases/fishing") print(ds[1].shape, len(labels)) plot_df(ds[1], labels[1:], segment_id[1:])
def score(self, X, ground_truth, **kwargs): segment_id = self._segment_by_time(X, **kwargs) h = harmonic_mean(ground_truth, segment_id) #print("Scoring "+','.join('{0}={1!r}'.format(k, kwargs[k]) for k in kwargs),str(h)) return h