forked from moreo/QuaPy
Added first tests
This commit is contained in:
parent
3d544135f1
commit
d86c402916
|
@ -0,0 +1,5 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_import():
|
||||||
|
import quapy as qp
|
||||||
|
assert qp.__version__ is not None
|
|
@ -0,0 +1,18 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from quapy.data.datasets import REVIEWS_SENTIMENT_DATASETS, TWITTER_SENTIMENT_DATASETS_TEST, \
|
||||||
|
TWITTER_SENTIMENT_DATASETS_TRAIN, UCI_DATASETS, fetch_reviews, fetch_twitter, fetch_UCIDataset
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dataset_name', REVIEWS_SENTIMENT_DATASETS)
|
||||||
|
def test_fetch_reviews(dataset_name):
|
||||||
|
fetch_reviews(dataset_name)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dataset_name', TWITTER_SENTIMENT_DATASETS_TEST + TWITTER_SENTIMENT_DATASETS_TRAIN)
|
||||||
|
def test_fetch_twitter(dataset_name):
|
||||||
|
fetch_twitter(dataset_name)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dataset_name', UCI_DATASETS)
|
||||||
|
def test_fetch_UCIDataset(dataset_name):
|
||||||
|
fetch_UCIDataset(dataset_name)
|
|
@ -0,0 +1,29 @@
|
||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
from sklearn.linear_model import LogisticRegression
|
||||||
|
from sklearn.naive_bayes import MultinomialNB
|
||||||
|
from sklearn.svm import LinearSVC
|
||||||
|
|
||||||
|
import quapy as qp
|
||||||
|
|
||||||
|
datasets = [qp.datasets.fetch_twitter('semeval16')]
|
||||||
|
|
||||||
|
aggregative_methods = [qp.method.aggregative.CC, qp.method.aggregative.ACC, qp.method.aggregative.ELM]
|
||||||
|
|
||||||
|
learners = [LogisticRegression, MultinomialNB, LinearSVC]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dataset', datasets)
|
||||||
|
@pytest.mark.parametrize('aggregative_method', aggregative_methods)
|
||||||
|
@pytest.mark.parametrize('learner', learners)
|
||||||
|
def test_aggregative_methods(dataset, aggregative_method, learner):
|
||||||
|
model = aggregative_method(learner())
|
||||||
|
|
||||||
|
model.fit(dataset.training)
|
||||||
|
|
||||||
|
estim_prevalences = model.quantify(dataset.test.instances)
|
||||||
|
|
||||||
|
true_prevalences = dataset.test.prevalence()
|
||||||
|
error = qp.error.mae(true_prevalences, estim_prevalences)
|
||||||
|
|
||||||
|
assert type(error) == numpy.float64
|
Loading…
Reference in New Issue