def test_edge1(self): """ Edge test on get_one_hot to check that ValueError is raised when label in data is not present in list. """ with self.assertRaises(ValueError): biome.get_one_hot(['cat', 'dog'], np.array([['kitten']]))
def test_shot1(self): """ One-shot test on get_one_hot to check that one-hot encoding is correctly performed. """ self.assertTrue( (biome.get_one_hot(['cat', 'dog'], np.array([['cat'], ['dog']])) == np.array([[1, 0], [0, 1]])).all())
import numpy as np from sklearn.datasets import make_classification import biome x, y = make_classification() x = np.array(x) y = np.array(y) y_data = [] for i in range(len(y)): if y[i] == 1: y_data.append(['cat']) else: y_data.append(['dog']) y_np = np.array(y_data) y_onehot = biome.get_one_hot(['cat', 'dog'], y_np) class TestSelectModel(unittest.TestCase): """ This class contains 3 smokes tests and an edge test for the functions: get_trained_models, evaluate_rank_models, and get_prediction. Since these algorithms each have their own unittest, the accuracy of these models will not be focused on. """ def test_smoke1(self): """ Smoke test on get_trained_models to check that a list is returned and is the correct length given the input. """ model_list = ['mlp1', 'mlp3', 'dtree']
OTU_path = input('Please enter the relative path to the OTU data: ') print('') metadata_path = input( 'Please enter the relative path to the categorical data: ') print('') category_labels = list( (input('Please list the categorical variables of interest: ')).split(',')) print('') print('What models would you like to test?') model_list = list( input('See README.md for abbreviations. Type all if all models should be ' 'tested: ').split(',')) print('') x_data, y_data = biome.data_loader(OTU_path, metadata_path) y_output = biome.get_one_hot(category_labels, y_data) x_train_unscale, x_test_unscale, y_train, y_test =\ biome.split_train_test(x_data, y_output) scaler = preprocessing.StandardScaler().fit(x_train_unscale) x_train = scaler.transform(x_train_unscale) x_test = scaler.transform(x_test_unscale) model_out = biome.evaluate_rank_models(x_train, y_train, x_test, y_test, model_list) model_name = model_out[0] best_model = model_out[1] yes_no = input('Would you like to make a prediction with the best model? ') print('') while yes_no == 'yes' or yes_no == 'Yes':