🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Persistency > 您可以保存经过培训的模型以备将来使通过将序列化估算器保存和恢复到文件中实现的请求之间的持久性。 ### 例 ``` use Phpml\Classification\KNearestNeighbors; use Phpml\ModelManager; $samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]]; $labels = ['a', 'a', 'a', 'b', 'b', 'b']; $classifier = new KNearestNeighbors(); $classifier->train($samples, $labels); $filepath = '/path/to/store/the/model'; $modelManager = new ModelManager(); $modelManager->saveToFile($classifier, $filepath); $restoredClassifier = $modelManager->restoreFromFile($filepath); $restoredClassifier->predict([3, 2]); // return 'b' ```