from core.datasets.classic.ClassicDataset import ClassicDataset
from sklearn.datasets import fetch_openml

import numpy as np
import pandas as pd


class GlassDataset(ClassicDataset):
    def __init__(self, seed):
        self.dataset = fetch_openml(data_id=41, as_frame=True)

        super().__init__(
            name='glass',
            num_classes=7,
            num_features=9,
            sample_shape=(9,),
            feature_names=self.dataset.feature_names,
            seed=seed
        )

    def _get_x_y(self):
        x = np.asarray(self.dataset.data)
        y = np.asarray(self.dataset.target)

        # Convert string targets to integer labels 0-6.
        y, _ = pd.factorize(y)

        return x, y
