本文整理汇总了Python中sklearn.linear_model.RidgeCV.log_predictive_density方法的典型用法代码示例。如果您正苦于以下问题:Python RidgeCV.log_predictive_density方法的具体用法?Python RidgeCV.log_predictive_density怎么用?Python RidgeCV.log_predictive_density使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.RidgeCV
的用法示例。
在下文中一共展示了RidgeCV.log_predictive_density方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enumerate
# 需要导入模块: from sklearn.linear_model import RidgeCV [as 别名]
# 或者: from sklearn.linear_model.RidgeCV import log_predictive_density [as 别名]
#preds, vars = model.predict_noiseless(X_test, Y_metadata=noise_dict)
for emo_id, emo in enumerate(EMOS):
# TODO: preprocessing
emo_dict = {}
to_predict = np.concatenate((X_test_list[emo_id], np.ones((X_test.shape[0], 1)) * emo_id), axis=1)
noise_dict = {'output_index': np.ones((X_test.shape[0], 1), dtype=int) * (emo_id)}
preds, vars = model.predict(to_predict, Y_metadata=noise_dict)
#if args.label_preproc == 'scale':
# preds = Y_scaler_list[emo_id].inverse_transform(preds)
emo_dict['mae'] = MAE(preds, Y_test_list[emo_id])
emo_dict['rmse'] = np.sqrt(MSE(preds, Y_test_list[emo_id]))
emo_dict['pearsonr'] = pearsonr(preds.flatten(), Y_test_list[emo_id].flatten())
#Y_metadata = {}
#Y_metadata['output_index'] = np.ones(X_test.shape[0]) * emo_id
emo_dict['nlpd'] = -np.mean(model.log_predictive_density(to_predict,
Y_test_list[emo_id],
Y_metadata=noise_dict))
info_dict[emo] = emo_dict
preds_list.append(preds.flatten())
vars_list.append(vars.flatten())
# Get parameters
if args.model == 'ridge':
info_dict['coefs'] = list(model.coef_)
info_dict['intercept'] = model.intercept_
info_dict['regularization'] = model.alpha_
elif args.model == 'svr':
info_dict['regularization'] = model.best_params_['C']
info_dict['epsilon'] = model.best_params_['epsilon']
info_dict['gamma'] = model.best_params_['gamma']
else:
示例2: MAE
# 需要导入模块: from sklearn.linear_model import RidgeCV [as 别名]
# 或者: from sklearn.linear_model.RidgeCV import log_predictive_density [as 别名]
preds = model.predict(X_test)
if args.label_preproc == 'scale':
preds = Y_scaler.inverse_transform(preds)
info_dict['mae'] = MAE(preds, Y_test.flatten())
info_dict['rmse'] = np.sqrt(MSE(preds, Y_test.flatten()))
info_dict['pearsonr'] = pearsonr(preds, Y_test.flatten())
else:
# TODO: check if this makes sense
#preds, vars = model.predict(X_test)
preds, vars = model.predict_noiseless(X_test)
if args.label_preproc == 'scale':
preds = Y_scaler.inverse_transform(preds)
info_dict['mae'] = MAE(preds, Y_test)
info_dict['rmse'] = np.sqrt(MSE(preds, Y_test))
info_dict['pearsonr'] = pearsonr(preds.flatten(), Y_test.flatten())
nlpd = model.log_predictive_density(X_test, Y_test)
info_dict['nlpd'] = np.mean(nlpd)
# Get parameters
if args.model == 'ridge':
info_dict['coefs'] = list(model.coef_)
info_dict['intercept'] = model.intercept_
info_dict['regularization'] = model.alpha_
elif args.model == 'svr':
info_dict['regularization'] = model.best_params_['C']
info_dict['epsilon'] = model.best_params_['epsilon']
info_dict['gamma'] = model.best_params_['gamma']
elif args.model == 'rbf':
info_dict['variance'] = float(model['rbf.variance'])
info_dict['lengthscale'] = list(model['rbf.lengthscale'])
info_dict['noise'] = float(model['Gaussian_noise.variance'])