Open In App

Shell Script to Export ML Model to Stakeholders

One challenge that we have particularly faced in our career is being able to efficiently send ML model results to business stakeholders. Although many companies/teams will have their internal tools or mechanisms to distribute ML model results to business stakeholders, many startups or new teams lack such mechanisms and need a way to bootstrap a process for immediate impact.

In this article, we will see how to export machine learning model results to stakeholders using a Shell script.



Stepwise implementation 

Step 1: Setting up a shell script

Open terminal on your system and run the following



vi shell_script.sh 

Then copy paste the below code. This code essentially reads all the records in your model output file row by row and sends an email to business stakeholders for every record in the model output file and then sends a collective report to all the emails to the email specified 

#!bin/bash

if [ -e $1 ]

then

while IFS = read -r line; do

  echo “Hello, record $line has been generated from the ML model” | mailx -s “ML Model daily results” business@xyz.com

done < $1

echo “Cases sent by ML model $(cat $1 | xargs | sed -e ‘s/ /./g’)” | mailx -s “Results sent from ML model to business stakeholders” username@xyz.com

else

echo “ML model results have been delayed” | mailx -s “ML Model execution has been delayed” username@xyz.com

Save the above file by pressing esc followed by “:wq!” To save changes made to the file.

Step 2: Executing the above script

You can run the above shell script by specifying the model output file location and running the following command

sh shell_script.sh model_results/daily_run_01172022.csv

Step 3: Automating the script using a cronjob

Open the crontab on your machine by running the following command

crontab -e

Now, you can create a cadence at which you want to execute the shell script.

0 1 * * 0 – 5 sh shell_script.sh model_results/daily_run_01172022.csv

With the above command, we are scheduling the script to execute 6 days in a week at 1 am.

Output:

Article Tags :