DimaPhil commited on
Commit ·
f005688
1
Parent(s): 7ccf28e
Fix dataset loading script
Browse files- wine-quality.py +16 -22
wine-quality.py
CHANGED
|
@@ -1,31 +1,25 @@
|
|
| 1 |
-
from datasets import DatasetBuilder, Csv
|
| 2 |
-
import os
|
| 3 |
import csv
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
class WineQuality(DatasetBuilder):
|
| 7 |
VERSION = "1.0.0"
|
| 8 |
-
BUILDER_CONFIG_CLASS = Csv.BuilderConfig
|
| 9 |
-
BUILDER_CONFIGS = [
|
| 10 |
-
Csv.BuilderConfig(name="winequality-red", version=VERSION, delimiter=";", encoding="utf-8"),
|
| 11 |
-
Csv.BuilderConfig(name="winequality-white", version=VERSION, delimiter=";", encoding="utf-8"),
|
| 12 |
-
]
|
| 13 |
|
| 14 |
def _info(self):
|
| 15 |
-
return
|
| 16 |
-
description="This is the dataset of Wine Quality,
|
| 17 |
-
|
| 18 |
|
| 19 |
def _split_generators(self, dl_manager):
|
| 20 |
-
|
| 21 |
-
datasets.SplitGenerator(name="red", gen_kwargs={"filepath": os.path.join(
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def _generate_examples(self, filepath):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
yield id_, row
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import csv
|
| 2 |
+
import os
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 5 |
|
| 6 |
+
class WineQuality(GeneratorBasedBuilder):
|
|
|
|
| 7 |
VERSION = "1.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def _info(self):
|
| 10 |
+
return DatasetInfo(
|
| 11 |
+
description="This is the dataset of Wine Quality, it consists of two parts: red and white"
|
| 12 |
+
)
|
| 13 |
|
| 14 |
def _split_generators(self, dl_manager):
|
| 15 |
+
if self.config.name == "red":
|
| 16 |
+
return [datasets.SplitGenerator(name="red", gen_kwargs={"filepath": os.path.join(dl_manager.dataset_dir, "winequality-red.csv")})]
|
| 17 |
+
elif self.config.name == "white":
|
| 18 |
+
return [datasets.SplitGenerator(name="white", gen_kwargs={"filepath": os.path.join(dl_manager.dataset_dir, "winequality-white.csv")})]
|
| 19 |
+
else:
|
| 20 |
+
raise NotImplementedError("This builder config is not implemented.")
|
| 21 |
|
| 22 |
def _generate_examples(self, filepath):
|
| 23 |
+
df = pd.read_csv(filepath_path, delimiter=";")
|
| 24 |
+
for id_, row in df.iterrows():
|
| 25 |
+
yield id_, row.to_dict()
|
|
|
|
|
|
|
|
|