Datasets:
Upload sonar.py
Browse files
sonar.py
CHANGED
@@ -21,7 +21,7 @@ urls_per_split = {
|
|
21 |
features_types_per_config = {
|
22 |
"sonar": {str(i): datasets.Value("float32") for i in range(60)}
|
23 |
}
|
24 |
-
features_types_per_config["sonar"]["
|
25 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
26 |
|
27 |
|
@@ -58,7 +58,7 @@ class Sonar(datasets.GeneratorBasedBuilder):
|
|
58 |
|
59 |
def _generate_examples(self, filepath: str):
|
60 |
data = pandas.read_csv(filepath, header=None)
|
61 |
-
data.columns = [str(i) for i in range(
|
62 |
data = self.preprocess(data, config=self.config.name)
|
63 |
|
64 |
for row_id, row in data.iterrows():
|
@@ -67,6 +67,6 @@ class Sonar(datasets.GeneratorBasedBuilder):
|
|
67 |
yield row_id, data_row
|
68 |
|
69 |
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
70 |
-
data.loc[:, "
|
71 |
|
72 |
return data
|
|
|
21 |
features_types_per_config = {
|
22 |
"sonar": {str(i): datasets.Value("float32") for i in range(60)}
|
23 |
}
|
24 |
+
features_types_per_config["sonar"]["is_rock"] = datasets.ClassLabel(num_classes=2)
|
25 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
26 |
|
27 |
|
|
|
58 |
|
59 |
def _generate_examples(self, filepath: str):
|
60 |
data = pandas.read_csv(filepath, header=None)
|
61 |
+
data.columns = [str(i) for i in range(60)] + ["is_rock"]
|
62 |
data = self.preprocess(data, config=self.config.name)
|
63 |
|
64 |
for row_id, row in data.iterrows():
|
|
|
67 |
yield row_id, data_row
|
68 |
|
69 |
def preprocess(self, data: pandas.DataFrame, config: str = DEFAULT_CONFIG) -> pandas.DataFrame:
|
70 |
+
data.loc[:, "is_rock"] = data["is_rock"].apply(lambda x: 1 if x == "R" else 0)
|
71 |
|
72 |
return data
|