File size: 2,845 Bytes
1e1b538
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from datasets import DatasetBuilder, DownloadManager, DatasetInfo, BuilderConfig, SplitGenerator, Split, Features, Value
import pandas as pd

# Define custom configurations for the dataset
class CryptoDataConfig(BuilderConfig):
    def __init__(self, features, **kwargs):
        super().__init__(**kwargs)
        self.features = features

class CryptoDataDataset(DatasetBuilder):
    # Define different dataset configurations here
    BUILDER_CONFIGS = [
        CryptoDataConfig(
            name="candles",
            description="This configuration includes open, high, low, close, and volume.",
            features=Features({
                "date": Value("string"),
                "open": Value("float"),
                "high": Value("float"),
                "low": Value("float"),
                "close": Value("float"),
                "volume": Value("float")
            })
        ),
        CryptoDataConfig(
            name="indicators",
            description="This configuration extends basic CryptoDatas with RSI, SMA, and EMA indicators.",
            features=Features({
                "date": Value("string"),
                "open": Value("float"),
                "high": Value("float"),
                "low": Value("float"),
                "close": Value("float"),
                "volume": Value("float"),
                "rsi": Value("float"),
                "sma": Value("float"),
                "ema": Value("float")
            })
        ),
    ]

    def _info(self):
        return DatasetInfo(
            description=f"CryptoData dataset for {self.config.name}",
            features=self.config.features,
            supervised_keys=None,
            homepage="https://hub.huggingface.co/datasets/sebdg/crypto_data",
            citation="No citation for this dataset."
        )

    def _split_generators(self, dl_manager: DownloadManager):
        # Here, you can define how to split your dataset (e.g., into training, validation, test)
        # This example assumes a single CSV file without predefined splits.
        # You can modify this method if you have different needs.
        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={"filepath": "indicators.csv"},
            ),
        ]

    def _generate_examples(self, filepath):
        # Here, we open the provided CSV file and yield each row as a single example.
        with open(filepath, encoding="utf-8") as csv_file:
            data = pd.read_csv(csv_file)
            for id, row in data.iterrows():
                # Select features based on the dataset configuration
                features = {feature: row[feature] for feature in self.config.features if feature in row}
                yield id, features