def _save_dataset(self, X, y): """ It saves the dataset that will be used to classify (helpful for plotting). Parameters ---------- X : pandas dataframe dataframe of features length: point features * motion features y : pandas dataframe class labels study : str name of previous work can be: "zheng", "dabiri", "xiao", or "jiang" """ # Save dataset create_folder(self.folder_baseline) point_features = ["mean", "std"] #["min", "max", "mean", "std"] colnames = list(product(self.motion_features, point_features)) colnames = list(map("_".join, colnames)) colnames = ["classes"] + colnames data = pd.concat([y, X], axis=1, ignore_index=True) data.columns = colnames filename = self.folder_baseline + "DATASET_baseline.csv" data.to_csv(filename, index=False)
def _save_dataset(self, X, y, parameter): """ It saves the dataset that will be used to classify (helpful for plotting). Parameters ---------- X : pandas dataframe dataframe of features y : pandas dataframe class labels """ # Save dataset create_folder(self.folder_classification) ## get feature name colnames_op = self._colnames(self.op_features) colnames = ["classes"] + colnames_op name = "_op_" + str(parameter) + ".csv" data = pd.concat([y, X], axis=1, ignore_index=True) data.columns = colnames filename = self.folder_classification + "DATASET_" + name data.to_csv(filename, index=False)
def _save_features(self, df_features, path_to_save, segment): """ This function saves the features extracted from trajectory. Parameters ---------- df_features : pandas dataframe the segment to save path_to_save : str absolute path where to save the segments segment : str the user's name Returns ------- no value """ ## save data user_path, file_name = split(segment) user_name = basename(dirname(user_path)) transportation_name = basename(user_path) ## where to save the features path_to_save = join(path_to_save, user_name, transportation_name, file_name) create_folder(path_to_save) df_features.to_csv(path_to_save, sep=",", header=True, index=None)
def _save_op_transformation(self, df_op, path_to_save, file_name): """ Saves the OP transformation. Parameters ---------- df_op : pandas dataframe the transformations to save path_to_save : str absolute path where to save the df file_name : str name to save data Returns ------- no value """ ## save data path_to_save = join(path_to_save, file_name) create_folder(path_to_save) df_op.to_csv(path_to_save, sep=",", header=True, index=None)
def _save_results(self, df, file_name): """ It saves the classification results (metrics and confusion matrices) in the self.folder_baseline (it will create the folder, if it doesn't exist). Parameters ---------- df : pandas dataframe the results to save file_name : str the name to save the result Returns ------- no value """ create_folder(self.folder_baseline) path_to_save = join(self.folder_baseline, file_name) try: df.to_csv(path_to_save, sep=",") except: # for confusion matrices df = np.array(df) with open(path_to_save, 'w') as outfile: for enum, data_slice in enumerate(df): if enum != 10: # Writing out a break to indicate different slices... outfile.write( '# Confusion Matrix for CV{}\n'.format(enum + 1)) else: outfile.write('# Total Confusion Matrix\n') np.savetxt(outfile, data_slice, fmt='%d')
def _save_segments(self, transport_name, segment, folder_segments, user_name): """ Saves the segments extracted from trajectory. Parameters ---------- transport_name : str the transportation used in the trajectory segment : pandas dataframe the segment to save path_to_save : str absolute path where to save the segments user_name : str the user's name Returns ------- no value """ path_to_save = join(folder_segments, user_name) ## write to file previous_traj = get_files(path_to_save, transport_name, False) k = len(previous_traj) + 1 ## where to save path_to_save = join(path_to_save, transport_name, "") create_folder(path_to_save) ## name to save file_name = "{}_{:03d}.csv".format(transport_name, k) save_in = join(path_to_save, file_name) segment.to_csv(save_in, sep = ",", header = True, index = None)