Mercurial > hg > plosone_underreview
comparison tests/test_classification.py @ 30:e8084526f7e5 branch-tests
additional test functions
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Wed, 13 Sep 2017 19:57:49 +0100 |
parents | |
children | d118b6ca8370 |
comparison
equal
deleted
inserted
replaced
29:6aa08c9c95e9 | 30:e8084526f7e5 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 Created on Fri Sep 1 19:11:52 2017 | |
4 | |
5 @author: mariapanteli | |
6 """ | |
7 | |
8 import pytest | |
9 | |
10 import numpy as np | |
11 from sklearn.model_selection import train_test_split | |
12 | |
13 import scripts.classification as classification | |
14 | |
15 | |
16 def test_confusion_matrix(): | |
17 X = np.random.randn(100, 3) | |
18 # create 2 classes by shifting the entries of half the samples | |
19 X[-50:, :] = X[-50:, :] + 10 | |
20 Y = np.concatenate([np.repeat('a', 50), np.repeat('b', 50)]) | |
21 X_train, X_test, Y_train, Y_test = train_test_split(X, Y, train_size=0.6, random_state=1, stratify=Y) | |
22 accuracy, predictions = classification.confusion_matrix(X_train, Y_train, X_test, Y_test) | |
23 # expect perfect accuracy for this 'easy' dataset | |
24 assert accuracy == 1.0 | |
25 |