python中的utils模块_Python utils 模块,evaluate() 实例源码 - 编程字典

def fit_evaluate(X_train, X_test, y_train, y_test, pipeline, n_min=10000):

pipeline_nm = utils.pipeline_name(pipeline)

print(pipeline_nm)

# Fit model

start_time = time.perf_counter()

pipeline.fit(X_train, y_train)

end_time = time.perf_counter()

print('Time elapsed to fit: {:.1f}s'.format(end_time - start_time))

# Evaluate model

start_time = time.perf_counter()

utils.evaluate(X_train, X_test, y_train, y_test, pipeline)

end_time = time.perf_counter()

print('Time elapsed to evaluate: {:.1f}s'.format(end_time - start_time))

# train_exponent = int(math.log10(len(X_train)))

# train_sample_n = int(math.pow(10, max(train_exponent - 2, 2)))

# train_sample_n = max(train_sample_n, min(n_min, len(X_train)))

train_sample_n = 10000

X_sample_train = X_train.sample(n=train_sample_n)

y_sample_train = y_train.reindex(X_sample_train.index)

test_exponent = int(math.log10(len(X_test)))

test_sample_n = int(math.pow(10, max(test_exponent - 2, 2)))

test_sample_n = max(test_sample_n, min(n_min, len(X_test)))

X_sample_test = X_test.sample(n=test_sample_n)

y_sample_test = y_test.reindex(X_sample_test.index)

# Visually inspect residuals for goodness of fitness

res_fig = utils.plot_residuals(X_sample_train,

X_sample_test,

y_sample_train,

y_sample_test,

pipeline)

res_fmt = 'output/residual_{}.png'

res_fig.savefig(res_fmt.format(pipeline_nm), dpi=200)

# Learning curve

start_time = time.perf_counter()

learn_fig = utils.plot_learning_curve([pipeline], X_sample_train, y_sample_train)

lc_fmt = 'output/learning_curve_{}.png'

learn_fig.savefig(lc_fmt.format(pipeline_nm), dpi=200)

end_time = time.perf_counter()

print('Time elapsed for learning curves: {:.1f}s'.format(end_time - start_time))

# Validation curve

# start_time = time.perf_counter()

# val_fig = utils.plot_validation_curve([pipeline],

# X_train,

# y_train,

# n_jobs=1)

# vc_fmt = 'output/validation_curve_{}.png'

# val_fig.savefig(vc_fmt.format(pipeline_nm), dpi=200)

# end_time = time.perf_counter()

# print('Time elapsed for validation curves: {:.1f}s'.format(end_time - start_time))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值