Sample the given dataset. input: records - a pandas dataframe with a 'text' column operation_function - a function that receives a cluster and returns an index output: a pandas dataframe with the sampled records
(self, records: pd.DataFrame, operation_function=random.choice)
| 76 | return clusters |
| 77 | |
| 78 | def sample(self, records: pd.DataFrame, operation_function=random.choice): |
| 79 | """ |
| 80 | Sample the given dataset. |
| 81 | input: records - a pandas dataframe with a 'text' column |
| 82 | operation_function - a function that receives a cluster and returns an index |
| 83 | output: a pandas dataframe with the sampled records |
| 84 | """ |
| 85 | |
| 86 | if not callable(operation_function): |
| 87 | raise ValueError("The 'operation_function' must be a callable function.") |
| 88 | |
| 89 | if self.clusters is None: |
| 90 | self.clusters = self.cluster_data(records) |
| 91 | |
| 92 | samples = [operation_function(list(cluster)) for cluster in self.clusters] |
| 93 | return records.iloc[sorted(samples)] |
no test coverage detected