Hello and welcome,
You may be able to use the joblib library to save and load your model object. It is a part of SciPy and therefore is installed on the Anvil servers. For example:
On your local machine:
# save the model to disk on your local machine
import joblib
.
.
.
joblib.dump(model, 'my_model.sav')
# Save that file into an Anvil datatable:
# You could write uplink code to transfer the file to Anvil or
# use the DataTables IDE to manually upload it or
# use a FileLoader component
# example of saving it to a data table using code (untested and from memory!):
anvil.server.connect(<uplink key>)
with open('my_model.sav', 'rb') as file:
media = anvil.BlobMedia(content_type='application/octet-streamf', content=file.read(), name='my_model_name')
app_tables.my_table.add_row(media_column=media)
On the Anvil Server:
import joblib
.
.
.
# load the model from disk (now on the Anvil server)
loaded_model = joblib.load('my_model.sav')
result = loaded_model.score(X_test, Y_test)
Similarly, if you can pickle your model, then you may be able to use Anvil’s cloudpickle
package to load the model back in. There may be other ways but this is what comes to mind.