MCPcopy Create free account
hub / github.com/Eladlev/AutoPrompt / sample

Method sample

utils/dedup.py:78–93  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)]

Callers 4

stepMethod · 0.80
remove_duplicatesMethod · 0.80
sample_recordsMethod · 0.80
large_error_to_strMethod · 0.80

Calls 1

cluster_dataMethod · 0.95

Tested by

no test coverage detected