我对Algorithmia还不太熟悉,但我使用过scikit-learn,并且知道如何在训练完机器学习模型后使用joblib进行持久化:
from sklearn.externals joblib
model = RandomForestRegressor()
# Train the model, etc
joblib.dump(model, "prediction/model/model.pkl")
现在我想使用Algorithmia托管我的ML模型并将其作为服务调用,但我无法弄清楚如何读取模型。我已经在Algorithmia中创建了一个名为“testcollection”的集合,其中包含一个名为“model.pkl”的文件,该文件是joblib.dump调用的结果。根据文档,这意味着我的文件应位于
data://(username)/testcollection/model.pkl
我希望使用joblib.load从文件中读取那个模型。以下是我在Algorithmia中的当前算法:
import Algorithmia
def apply(input):
client = Algorithmia.client()
f = client.file("data://(username)/testcollection/model.pkl")
print(f.path)
print(f.url)
print(f.getName())
model = joblib.load(f.url) # Or f.path, both don't work
return "empty"
这是输出结果:
(username)/testcollection/model.pkl
/v1/data/(username)/testcollection/model.pkl
model.pkl
在 joblib.load 行出现错误,显示“无此文件或目录(无论我输入什么路径)”。以下是我尝试调用 joblib.load 时的所有路径/URL:
- /v1/data/(username)/testcollection/model.pkl
- data://(username)/testcollection/model.pkl
- (username)/testcollection/model.pkl
- https://algorithmia.com/v1/data/(username)/testcollection/model.pkl
f.url
替换为f.name
。 路径和 URL 应该是 DataFile 对象内部的私有字段... 但这是 Python,所以没有什么是私有的。 - jamesatha