QuAcc/quacc/dataset.py

36 lines
1.1 KiB
Python
Raw Normal View History

2023-09-14 01:52:19 +02:00
from typing import Tuple
import numpy as np
from quapy.data.base import LabelledCollection
import quapy as qp
2023-09-14 01:52:19 +02:00
from sklearn.conftest import fetch_rcv1
2023-09-14 01:52:19 +02:00
TRAIN_VAL_PROP = 0.5
2023-09-13 00:11:20 +02:00
2023-09-14 01:52:19 +02:00
def get_imdb() -> Tuple[LabelledCollection]:
train, test = qp.datasets.fetch_reviews("imdb", tfidf=True).train_test
train, validation = train.split_stratified(train_prop=TRAIN_VAL_PROP)
return train, validation, test
def get_spambase():
train, test = qp.datasets.fetch_UCIDataset("spambase", verbose=False).train_test
train, validation = train.split_stratified(train_prop=TRAIN_VAL_PROP)
return train, validation, test
def get_rcv1(sample_size=100):
dataset = fetch_rcv1()
target_labels = [
(target, dataset.target[:, ind].toarray().flatten())
for (ind, target) in enumerate(dataset.target_names)
]
filtered_target_labels = filter(
lambda _, labels: np.sum(labels) >= sample_size, target_labels
)
return {
target: LabelledCollection(dataset.data, labels, classes=[0, 1])
for (target, labels) in filtered_target_labels
}