A few weeks ago, I was preparing my R scripts to deploy them in a SQL Server 2016 database. I had developed and tested my scripts locally and they worked great. I was able to train and store my model without any hiccups, however, when I went to run the stored procedure that I use to make predictions I got the following error.
Error: *** Exception: ‘Metadata KeyValues does not exist’
So, I started searching online trying to figure out what the problem was. I found nothing. Therefore, I started simplifying my scripts and reducing my dataset trying to locate the problem. After about an hour or two of troubleshooting I figured out what the problem was (or at least what I think the problem was).
When I trained my model, I ensured that each column was a specific data type in R, however, when I make predictions I forgot to convert one of the id columns in my dataset. The id column was not being used to make predictions, so initially I thought it was a little odd that this caused the error. Since it was not being used to predict any values I thought about removing the column, but I needed it in the result set so that I could link rows back to the original dataset. The id column was converted to a character vector when I was training my model, and when I was making predictions I did not explicitly convert the column to a character vector. This means that I was passing in a different data type than what the model was expecting. The inconsistent data type seemed to be causing the stored procedure to error. To fix this I simply needed to ensure that the id column was the correct type prior to making predictions on my dataset. This error seems to occur only when I use a machine learning algorithm from either the RevoScaleR and MicrosoftML libraries.
If you have any questions, please contact firstname.lastname@example.org.