将现有的Python SAV文件导入环境

时间:2019-01-11 16:32:04

标签: python python-3.x scipy

我正在尝试导入.sav文件(在python中生成的预测模型),但是进展不大。我使用过this tutorial,但仍然没有帮助。 models/是.sav文件所在的目录。任何帮助将不胜感激。

sc.io.readsav('models/Predictive_Model.sav', idict = 'model')

错误:

    724     signature = _read_bytes(f, 2)
    725     if signature != b'SR':
--> 726         raise Exception("Invalid SIGNATURE: %s" % signature)
    727 
    728     # Next, the record format, which is '\x00\x04' for normal .sav

Exception: Invalid SIGNATURE: b'\x80\x03'

1 个答案:

答案 0 :(得分:0)

使用Pickle保存模型:

# save the model to disk
filename = 'finalized_model.sav'
pickle.dump(model, open(filename, 'wb'))

# some time later...

# load the model from disk
loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_test, Y_test)
print(result)