代码之家  ›  专栏  ›  技术社区  ›  Randy Tang

保存一个scikit学习束对象

  •  0
  • Randy Tang  · 技术社区  · 5 年前

    如何保存一个scikit学习 Bunch 反对一个文件?目前,我将其保存到几个numpy文件中,这很麻烦:

    from sklearn.datasets import fetch_lfw_people
    
    # Save to files
    faces = fetch_lfw_people(min_faces_per_person=60)
    np.save('faces_data.npy', faces.data)
    np.save('faces_images.npy', faces.images)
    np.save('faces_target.npy', faces.target)
    np.save('faces_target_names.npy', faces.target_names)
    np.save('faces_descr.npy', faces.DESCR)
    
    # Read the files
    from sklearn.datasets.base import Bunch
    faces = Bunch()
    faces['data'] = np.load('faces_data.npy')
    faces['images'] = np.load('faces_images.npy')
    faces['target'] = np.load('faces_target.npy')
    faces['target_names'] = np.load('faces_target_names.npy')
    faces['DESCR'] = np.load('faces_descr.npy')
    
    0 回复  |  直到 5 年前
    推荐文章