本文整理汇总了Python中joblib.Parallel.tolist方法的典型用法代码示例。如果您正苦于以下问题:Python Parallel.tolist方法的具体用法?Python Parallel.tolist怎么用?Python Parallel.tolist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类joblib.Parallel
的用法示例。
在下文中一共展示了Parallel.tolist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from joblib import Parallel [as 别名]
# 或者: from joblib.Parallel import tolist [as 别名]
#.........这里部分代码省略.........
if version in ['100k', '1m', '10m']:
X = load_movielens(version)
X_tr, X_te = train_test_split(X, train_size=0.75,
random_state=random_state)
X_tr = X_tr.tocsr()
X_te = X_te.tocsr()
elif version is 'netflix':
X_tr = load(expanduser('~/spira_data/nf_prize/X_tr.pkl'))
X_te = load(expanduser('~/spira_data/nf_prize/X_te.pkl'))
cd_mf = ExplicitMF(n_components=60, max_iter=50, alpha=.1, normalize=True,
verbose=1, )
dl_mf = DictMF(n_components=30, n_epochs=20, alpha=1.17, verbose=5,
batch_size=10000, normalize=True,
fit_intercept=True,
random_state=0,
learning_rate=.75,
impute=False,
partial=False,
backend='python')
dl_mf_partial = DictMF(n_components=60, n_epochs=20, alpha=1.17, verbose=5,
batch_size=10000, normalize=True,
fit_intercept=True,
random_state=0,
learning_rate=.75,
impute=False,
partial=True,
backend='python')
timestamp = datetime.datetime.now().strftime('%Y-%m-%d_%H'
'-%M-%S')
if cross_val:
subdir = 'benches_ncv'
else:
subdir = 'benches'
output_dir = expanduser(join('~/output/recommender/', timestamp, subdir))
if not os.path.exists(output_dir):
os.makedirs(output_dir)
alphas = np.logspace(-2, 1, 10)
mf_list = [dl_mf_partial]
dict_id = {cd_mf: 'cd', dl_mf: 'dl', dl_mf_partial: 'dl_partial'}
names = {'cd': 'Coordinate descent', 'dl': 'Proposed online masked MF',
'dl_partial': 'Proposed algorithm (with partial projection)'}
if os.path.exists(join(output_dir, 'results_%s_%s.json' % (version,
random_state))):
with open(join(output_dir, 'results_%s_%s.json' % (version,
random_state)),
'r') as f:
results = json.load(f)
else:
results = {}
for mf in mf_list:
results[dict_id[mf]] = {}
if not cross_val:
if isinstance(mf, DictMF):
mf.set_params(
learning_rate=dl_params[version]['learning_rate'],
batch_size=dl_params[version]['batch_size'],
alpha=dl_params[version]['alpha'])
else:
mf.set_params(alpha=cd_params[version]['alpha'])
else:
if isinstance(mf, DictMF):
mf.set_params(
learning_rate=dl_params[version]['learning_rate'],
batch_size=dl_params[version]['batch_size'])
if version != 'netflix':
cv = ShuffleSplit(n_iter=3, train_size=0.66, random_state=0)
mf_scores = Parallel(n_jobs=n_jobs, verbose=10)(
delayed(single_fit)(mf, alpha, X_tr, cv) for alpha in
alphas)
else:
mf_scores = Parallel(n_jobs=n_jobs, verbose=10)(
delayed(single_fit)(mf, alpha, X_tr, X_te,
nested=False) for alpha in alphas)
mf_scores = np.array(mf_scores).mean(axis=1)
best_alpha_arg = mf_scores.argmin()
best_alpha = alphas[best_alpha_arg]
mf.set_params(alpha=best_alpha)
cb = Callback(X_tr, X_te, refit=False)
mf.set_params(callback=cb)
mf.fit(X_tr)
results[dict_id[mf]] = dict(name=names[dict_id[mf]],
time=cb.times,
rmse=cb.rmse)
if cross_val:
results[dict_id[mf]]['alphas'] = alphas.tolist()
results[dict_id[mf]]['cv_alpha'] = mf_scores.tolist()
results[dict_id[mf]]['best_alpha'] = mf.alpha
with open(join(output_dir, 'results_%s_%s.json' % (version,
random_state)),
'w+') as f:
json.dump(results, f)
print('Done')