0

Platform: ArcGIS Pro 3.0.4

Situation: I want to create a geoprocessing tool that uses a sklearn machine learning model (saved in .sav format). The goal is that users will be able to input a new table into the geoprocessing tool, the tool will apply the machine learning model, and then an output will be created from the results.

Question: Is there a way to include a .sav file (saved machine learning model) in a file or enterprise gdb?

2 Answers 2

0

Couple of thoughts:

  1. Could you just include the model file with the toolbox / tool and request they are in the same folder? Or is this being packaged up as a project package?

  2. I assume when you refer to a save model file you are using pickle to save the model? You could try saving the binary data to a geodatabase table with a BLOB column type.

  3. Depending on the model, create a geodatabase table with a column for each of the model's parameters storing the value of the parameter (sort of similar to the json approach here: https://medium.com/analytics-vidhya/save-and-load-your-scikit-learn-models-in-a-minute-21c91a961e9b)

0

In theory, you could have a featureclass inside a fGDB, and that FC has a single record with an attachment. That attachment could be your .sav file, and your Python tool could fetch and open that for use in your tool. (in theory). However this is the long, hard road to achieve your goal.

Based on how you framed your question, it seems you're trying to make your tool portable. Either zip it up and email it, have it on a fileshare and colleagues copy it -- somehow others will get this tool and make use of it.

I'd strongly encourage you to look at creating a Geoprocessing Package. This is basically a zip file of all the contents you need to run your tool. You share a single .gpkx file. Those using the file just open it in Pro, and the tool extracts automatically for them with all the required pieces. The only thing to note for you, the tool author is how you develop the tool before turning it into a package.

In your code, probably near the top, just create a reference to your model; the packaging process will identify the .sav file, bundle it into the package and fix the paths inside the code when extracting it. Do something like:

mySavFile = "c:\\machineLearning\\tool\\model.sav"
# this next part is made up, no idea how your module works
machineLearning.Thing.loadSave(mySavFile)  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.