Posted: 2024-01-12
This post is about practical challenges with data science.
At Process IQ we like Python and friends. It is a great language: it is expressive, easy to read and comes with fantastic set of libraries. However there are two things which are thorny with Python: deployments and no type safety.
This is our opinion - we are a small and agile tech company and we like efficiency that comes with type safety. Nonetheless, there are large companies, running Python applications at big scale e.g. Instagram, Google and YouTube, Dropbox or PayPal.
One activity where we use Python in production is machine learning, or rather machine “teaching”. Our data science team likes to use Python environment to experiment with models, and train them. However for production use we require models to be executed directly through the .NET runtime for security and stability reasons.
We also like Gradient Boosting Models for their expressiveness and efficiency with respect to required number of data samples. So here is a practical problem: how can you transfer a model from Python environment into .NET runtime?
Turns out that Microsoft has been pushing successfully ML.NET libraries which also ship with Onnx model format. Onnxmltools are able to translate industry standard sci-kit models so .NET can execute them directly. Here’s how:
import onnxmltools
from onnxmltools.convert.common.data_types import FloatTensorType
sci_kit_model = ...
onnx_model = onnxmltools.convert_lightgbm( sci_kit_model, initial_types=[('input', FloatTensorType([1,2]))] )
onnxmltools.utils.save_model(onnx_model, 'onnx.model')
The following code fragment shows how to use onnx model in C#.
private class TestData
{
[VectorType(2)]
public float[] input;
}
public class TestOutput
{
[ColumnName("label")]
[VectorType(1)]
public long[] Label { get; set; }
}
static void Main(string[] args)
{
var mlContext = new MLContext();
var data = mlContext.Data.LoadFromEnumerable( new TestData[] {});
var onnxPredictionPipeline = mlContext.Transforms
.ApplyOnnxModel("onnx.model");
var transformer = onnxPredictionPipeline.Fit(data);
var onnxPredictionEngine = mlContext.Model.CreatePredictionEngine<TestData, TestOutput>(transformer);
var prediction = onnxPredictionEngine.Predict(new TestData { input = new float[] { 0f, 0f } });
Console.WriteLine($"label: {string.Join(",", prediction.Label)}");
}
Pretty easy 😎. Our corporate cat is shocked!
Photo by Ariana Suárez on Unsplash
Posted: 2023-10-06
Almost everybody in professional setting has come to a brick wall caused by a computer system. Either it is a problem with a cumbersome data entry or a difficulty to trouble-shoot a record or trade in an ever increasing world of regulations or other complexities. The users frustration start building up, to the degree that they stop using the system! We’ve seen in our experience such actions, which derailed multi-million dollar investments led by established management consulting companies.
At Process IQ we solve those challenges by using Artificial Intelligence (sometimes called Machine Learning). Our mission is to enable our clients to focus on what they do the best: business. The boring stuff can be left to algorithms.
The typical process of rectifying a data problem at a financial organization quite often looks like this:
With AI we can simplify that:
The black box typically contains logistic regression or random forest ensemble, but the key is the feedback loop. By capturing good decisions and all bad, that the approver had to correct, the system learns from mistakes.
All those links are great, but how does it work in laymans terms? During learning process we are tweaking black box parameters to match what Approver selected. The parameters that give answers that are closest to the correct, are then used to provide recommendations. This is called supervised learning
At some point the science turns into art. How do you represent domain knowledge? What about curse of dimensionality? How to prevent over-fitting and how to optimize target function, are some of the questions that system designer is facing with. We strive for these challenges and our product CORTEX uses AI to reduce the boring stuff. So you can focus on more value add to the business.