Custom Model Checks

AkshayArora1
Level 2
Custom Model Checks

 

Can I get some examples of custom model checks

 

 

0 Kudos
1 Reply
AmandaM
Dataiker

Hi @AkshayArora1 , 

I have provided an example below of a custom python metric and then the corresponding check. The metric returns a boolean if the dataset has been modified that day. The corresponding check will pass if the dataset has been modified that day and fail otherwise. 

Hope this helps! 

## CUSTOM METRIC ##

import dataiku from datetime import datetime dataset = dataiku.Dataset(<YOUR DATASET>) # Define here a function that returns the metric. def process(dataset, partition_id): # dataset is a dataiku.Dataset object modifiedDate = dataset.get_files_info()['globalPaths'][0]['lastModified'] / 1000 modifiedDate = datetime.utcfromtimestamp(modifiedDate).date() today = datetime.now().date() modified_today = modifiedDate >= today return {'modified_today' : modified_today}
## CUSTOM CHECK ##
import dataiku dataset = dataiku.Dataset(<YOUR DATASET>) # Define here a function that returns the outcome of the check. def process(last_values, dataset, partition_id): # last_values is a dict of the last values of the metrics, # with the values as a dataiku.metrics.MetricDataPoint. # dataset is a dataiku.Dataset object m = dataset.get_last_metric_values() if m.get_metric_by_id('python:modified_today:Python probe')['lastValues'][0]['value'] == 'false': return "ERROR" return 'OK', 'optional message' # or 'WARNING' or 'ERROR'

 

0 Kudos