crypto_data / crypto_data.py
Sébastien De Greef
Add scripts to create indicators and sequences, and download crypto data
1e1b538
raw
history blame
2.85 kB
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