Creates a Pandas DataFrame object based off of the dataset's file extension, whether a GPU is available or not, whether the user wants the dataset to be trimmed or not, and the format of trimming specified by the user. NOTE: This function currently only supports .csv (comma
(self)
| 49 | return self.filepath[ext_index:] |
| 50 | |
| 51 | def data_generator(self): |
| 52 | ''' |
| 53 | Creates a Pandas DataFrame object based off of the dataset's file extension, whether a GPU is available or not, |
| 54 | whether the user wants the dataset to be trimmed or not, and the format of trimming specified by the user. |
| 55 | |
| 56 | NOTE: This function currently only supports .csv (comma-separated values file), |
| 57 | .xlsx (Microsoft Excel Open XML Spreadsheet), and .json (JavaScript Object Notation) files |
| 58 | |
| 59 | If the user's device contains a GPU, the dataset won't be trimmed unless the user specifies so. If the user's |
| 60 | device doesn't contain a GPU, the dataset will automatically be trimmed regardless of whether the user specified |
| 61 | for the dataset to be trimmed or not in order to ensure efficient processing by the CPU. |
| 62 | |
| 63 | If the user doesn't specify a specific form of trimming they want to apply to the dataset, random sampling will |
| 64 | be applied by default. |
| 65 | |
| 66 | If the user doesn't specify a proportion/ratio of how much of the dataset needs to be trimmed, 20% of the |
| 67 | dataset will be trimmed by default. |
| 68 | |
| 69 | :return: The dataset after being trimmed/pre-processed (Pandas DataFrame) |
| 70 | ''' |
| 71 | if self.retrieve_extension() == '.csv': |
| 72 | df = pd.read_csv(self.filepath) |
| 73 | elif self.retrieve_extension() == '.xlsx': |
| 74 | df = pd.read_excel(self.filepath) |
| 75 | for data in df: |
| 76 | if df[data].dtype.name == 'int64': |
| 77 | df[data] = df[data].astype(float) |
| 78 | elif self.retrieve_extension() == '.json': |
| 79 | df = pd.read_json(self.filepath) |
| 80 | |
| 81 | if self.is_gpu_available() == False: |
| 82 | self.trim = True |
| 83 | if self.trim: |
| 84 | if self.trim_format == 'random': |
| 85 | df = df.sample(frac=(1.0 - self.trim_ratio)) |
| 86 | # elif self.trim_format == 'stratify': |
| 87 | # # ADD STRATIFYING TECHNIQUE HERE |
| 88 | # y = df[self.strat_col] |
| 89 | # del df[self.strat_col] |
| 90 | # print(df.shape) |
| 91 | # x_train, x_test, y_train, y_test = train_test_split(df, y, stratify=y, test_size=0.1, random_state=0) |
| 92 | # |
| 93 | # df = pd.concat([x_test, y_test]) |
| 94 | # print(df.shape) |
| 95 | |
| 96 | return df |
| 97 | |
| 98 | def get_available_gpus(self): |
| 99 | ''' |
no test coverage detected