From the cloud to the edge: reverse-engineering and downsizing a black box ML algorithm