Unit testing
When creating your own functions and classes, it is always a good idea to do unit testing. Unit testing aims to test a single unit of your code. In this case, we want to test that our transformer does as it needs to do.
Good tests should be independently verifiable. A good way to confirm the legitimacy of your tests is by using another computer language or method to perform the calculations. In this case, I used Excel to create a dataset, and then computed the mean for each cell. Those values were then transferred to the unit test.
Unit tests should also, generally, be small and quick to run. Therefore, any data used should be of a small size. The dataset I used for creating the tests is stored in the Xt
variable from earlier, which we will recreate in our test. The mean of these two features is 13.5 and 15.5, respectively.
To create our unit test, we import theassert_array_equal
function from NumPy's
testing, which checks whether two arrays are equal:
from numpy.testing import...