def test_fit_ko_not_found(self): """ Tests the execution failure when the population is not readable from the processdata in DB. """ with self.assertRaises(IkatsNotFoundError): fit(population="no_table", target_column_name='"Species"', identifier_column_name="Id", max_depth=0, balanced_class_weight=False)
def test_fit_population_sklearn_ko(self): """ Tests the unexpected error, raised by algorithm """ with self.assertRaises(IkatsException): fit(population="iris", target_column_name='"Species"', identifier_column_name="Id", max_depth=0, balanced_class_weight=False)
def test_fit_nominal_from_id(self): """ Tests the nominal execution based upon mock data: IRIS data """ _, mdl, dot = fit(population="iris", target_column_name='"Species"', identifier_column_name="Id", max_depth=0, balanced_class_weight=False) # trained: 71,5.9,3.2,4.8,1.8,I. versicolor # => test below should obtain same class: # # mdl.predict([[5.9, 3.2, 4.8, 1.8]]) returns a numpy.ndarray # so we have to convert predicted value to str: for x_val, ref_predict in [[[5.9, 3.2, 4.8, 1.8], "I. versicolor"], [[ 5.7, 2.8, 4.1, 1.3, ], "I. versicolor"], [[5.9, 3.0, 5.1, 1.8], "I. virginica"]]: predicted = "{}".format(mdl.predict([x_val])[0]) self.assertEqual( predicted, ref_predict, "Failed to use the computed model: predict x={}".format(x_val)) self.assertEqual(type(dot), str, "Bad type for the dot returned")
def test_predict_nominal(self): """ Tests the nominal execution based upon mock data: IRIS data tests data originated from mocked iris dataset => accuracy = 100% """ _, mdl, _ = fit(population="iris", target_column_name='"Species"', identifier_column_name="Id", max_depth=0, balanced_class_weight=False) test_table = { "table_desc": {}, "headers": { "col": { "data": [ "Id", "Sepal length", "Sepal width", "Petal length", "Petal width", "Species" ] }, "row": { "data": [None, "1", "5", "8", "128"] } }, "content": { "cells": [["5.9", "3.2", "4.8", "1.8", "I. versicolor"], ["5.0", "3.5", "1.6", "0.6", "I. setosa"], ["5.9", "3.0", "5.1", "1.8", "I. virginica"], ["6.8", "3.0", "5.5", "2.1", "I. virginica"]] } } attempted_matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 2]] # Create the table used for this test create_table(name="pop_table", data=test_table) table_name, accuracy = predict(model=mdl, population_name="pop_table", target_column_name='Species', identifier_column_name='Id', table_name='my_table') matrix = IkatsApi.table.read(table_name) self.assertListEqual(matrix['content']['cells'], attempted_matrix) self.assertEqual(accuracy, 1)
def test_fit_with_depth(self): """ Tests the nominal execution based upon mock data: IRIS data """ _, mdl, dot = fit(population="iris", target_column_name='"Species"', identifier_column_name="Id", max_depth=4, balanced_class_weight=True) # trained: 71,5.9,3.2,4.8,1.8,I. versicolor # => test below should obtain same class: # # mdl.predict([[5.9, 3.2, 4.8, 1.8]]) retuns a numpy.ndarray # so we have to convert predicted value to str: predicted = "{}".format(mdl.predict([[5.9, 3.2, 4.8, 1.8]])[0]) self.assertEqual(predicted, "I. versicolor", "Failed to use the computed model") self.assertEqual(type(dot), str, "Bad type for the dot returned")