MLOPs Zoomcamp (Week 6)

MLOPs Zoomcamp (Week 6)

Best Engineering Practices

Introduction

Almost in all engineering fields, there are a set of best practices and standards that engineers follow while performing their task. In week-6 of mlops-zoomcamp, we learned about best engineering practices in the field. When its time to move from development to production, there are a series of standard checks and practices that must be followed and conducted in order to ensure everything works fine and as expected. Besides this, these best practices are industry standards that are accepted worldwide. Some of the major topics that were discussed are testing and code quality.

Testing

Testing is very important part of every software development lifecycle. Testing is the process of evaluating and verifying that a software product or application does what it is supposed to do. During testing, we create all sorts of possible input values that a software might receive in real world and observe the output. There are two types of testing:

  • Unit test
  • Integration test

In unit test, we test single smallest testable parts of a software being tested. In simpler words, if we test the batch deployment of machine learning model (week-4), then unit test comprises of testing of various individual functions we defined. Unit tests are actually very useful because they help us to identify the issues and problems at the very lowest level. Let's consider a simple function for unit testing.

dummy.py

def sum(a,b):
   return a+b

test_dummy.py

from dummy import sum

def test_sum():
   a = 5
   b = 4
   c = sum(a,b)
   assert c == 9

In order to test a function, we need to import it and in our case, we will use pytest framework for unit testing. We will pass different input values (a,b) and assert if the outcome is as expected or not. We can use the command below to run the test.

$ python -m pytest test_dummy.py

While unit test tests small units of a large module, integration test is exact opposite of that. Integration testing is the phase is software testing in which individual functions are combined and tested as a group. It is done to test the modules or pieces of code (functions) which are working fine individually, does not have issues when integrated. A simple integration test is given below:

profit.py

def profit_amt(sp, cp):
   return sp-cp

def profit_percent(profit, cp):
   return (profit / cp) * 100

Assuming the individual functions in above snippet work fine, we will perform integration test to see the functions work when integrated as well.

integration_test.py

from profit import profit_amt, profit_percent

sp = 1000
cp = 800
profit_amount = profit_amt(sp, cp)
profit_percentage = profit_percent(profit_amount, cp)

assert profit_percentage == 25

Apart from testing, we learned about code quality. To ensure, our code quality is as per standard, we will use pylint python framework, which performs quality checks on our code such as checking the documentation of functions.

This blog gives a high level overview of week-06 in mlops-zoomcamp. If you are interested in moving beyond notebooks and putting the models into production, then check out the #mlops-zoomcamp course.