本文整理汇总了Python中cache.Cache.save_file方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.save_file方法的具体用法?Python Cache.save_file怎么用?Python Cache.save_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.save_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_feature_ids
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import save_file [as 别名]
def load_feature_ids(self):
if os.path.exists(self.DEV_IDS_PATH) and os.path.exists(self.TEST_IDS_PATH):
movie_ids = (
Cache.load_file(self.DEV_IDS_PATH) +
Cache.load_file(self.TEST_IDS_PATH)
)
else:
movie_ids = [id[0] for id in self.fetch_distinct_ids()]
test_sample_size = int(math.floor(self.TEST_PROB * len(movie_ids)))
test_ids = random.sample(movie_ids, test_sample_size)
dev_ids = list(set(movie_ids) - set(test_ids))
Cache.save_file(self.DEV_IDS_PATH, dev_ids)
Cache.save_file(self.TEST_IDS_PATH, test_ids)
logging.info("Loaded %s Movie IDs" % (len(movie_ids)))
return movie_ids
示例2: save_kmeans_features
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import save_file [as 别名]
def save_kmeans_features(self, model, model_name):
logging.info("Preparing to save kmeans features...")
logging.info("Reloading features.")
features = json.load(open('data/features.json'))
logging.info("Generating clusters for data")
training_predictions = model.predict(self.training_feature_matrix)
test_predictions = model.predict(self.predict_feature_matrix)
logging.info("Finished Generating Clusters for data")
movie_id_clusters = [[self.dev_movie_ids, training_predictions], [self.test_movie_ids, test_predictions]]
for movie_ids, clusters in movie_id_clusters:
if len(movie_ids) != len(clusters):
raise ValueError('Movie ids don\'t match clusters')
for movie_id, cluster in itertools.izip(movie_ids, clusters):
features[str(movie_id)]['features']['cluster_%s' % cluster] = 1
logging.info("Saving cluster features")
Cache.save_file(os.path.join('data', 'features_%s.json' % model_name), features)
示例3: save_features
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import save_file [as 别名]
def save_features(self):
Cache.save_file(self.FEATURES_PATH, self.features)
示例4: save_weights
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import save_file [as 别名]
def save_weights(self, weights):
WEIGHTS_PATH = os.path.join('data', 'weights.json')
Cache.save_file(WEIGHTS_PATH, weights)