Microsoft introduced native predictive model scoring with the release of SQL Server 2017.
The PREDICT function (Documentation) is now a native T-SQL function that eliminates having to score using R or Python through the sp_execute_external_script procedure. It’s an alternative to sp_rxPredict. In both cases you do not need to install R but with PREDICT you do not need to enable SQLCLR either – it’s truly native.
PREDICT should make predictions much faster as the process avoids having to marshal the data between SQL Server and Machine Learning Services (Previously R Services).
Migrating from the original sp_execute_external_script approach to the new native approach tripped me up so I thought I’d share a quick summary of what I have learned.
Stumble One:
Error occurred during execution of the builtin function 'PREDICT' with HRESULT 0x80004001.
Model type is unsupported.
Reason:
Not all models are supported. At the time of writing, only the following models are supported:
- rxLinMod
- rxLogit
- rxBTrees
- rxDtree
- rxdForest
sp_rxPredict supports additional models including those available in the MicrosoftML package for R (I was using attempting to use rxFastTrees). I presume this limitation will reduce over time. The list of supported models is referenced in the PREDICT function (Documentation).
Stumble Two:
Error occurred during execution of the builtin function 'PREDICT' with HRESULT 0x80070057.
Model is corrupt or invalid.
Reason:
The serialisation of the model needs to be modified for use by PREDICT. Typically you might serialise your model in R like this:
model <- data.frame(model=as.raw(serialize(model, NULL)))
Instead you need to use the rxSerializeModel method:
model <- data.frame(rxSerializeModel(model, realtimeScoringOnly = TRUE))
There’s a corresponding rxUnserializeModel method, so it’s worth updating the serialisation across the board so models can be used interchangeably in the event all models are eventually supported. I have been a bit legacy.
That’s it. Oh, apart from the fact PREDICT is supported in Azure SQL DB, despite the documentation saying the contrary.
Pareto Charts in Power BI and the DAX behind them
The Pareto principle, commonly referred to as the 80/20 rule, is a concept of prioritisation.
Apr
Databricks: Cluster Configuration
Databricks, a cloud-based platform for data engineering, offers several tools that can be used to
Apr
AI Assistance in Microsoft Fabric
The exponential growth of Large Language Models (LLMs) couples with Microsoft’s close partnership with OpenAI
Apr
10 reasons why it’s worth the effort to understand the value of your data
“If leaders really want to create a data driven culture, the journey starts with them!
Apr
Content Safety in Azure AI Studio
Azure AI Content Safety is a solution designed to identify harmful content, whether generated by
Apr
Model Benchmarks in Azure AI Studio
In the constantly changing field of artificial intelligence (AI) and machine learning (ML), choosing the
Apr
Celebrating International Women’s Day: from Classroom to Code
As we celebrate International Women’s Day, I want to share my journey of breaking stereotypes
Mar
Pretty Power BI – Adding Pagination to Bar Charts
Good User Experience (UX) design is crucial in enabling stakeholders to maximise the insights that
Feb