Skip to Content
机器学习速查手册
book

机器学习速查手册

by Matt Harrison
July 2025
Intermediate to advanced
320 pages
3h 10m
Chinese
O'Reilly Media, Inc.
Content preview from 机器学习速查手册

第 11 章 模型选择 模型选择

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

本章将讨论优化超参数。本章还将探讨模型是否需要更多数据才能表现更好的问题。

验证曲线

创建验证曲线是确定超参数适当值的一种方法。 验证曲线是显示模型性能如何响应超参数值变化的曲线图(见图 11-1)。图表同时显示了训练数据和验证数据。通过验证分数,我们可以推断出模型对未知数据的响应情况。通常情况下,我们会选择一个能使验证得分最大化的超参数。

在下面的示例中,我们将使用 Yellowbrick 来观察改变max_depth超级参数的值是否会改变随机森林的模型性能。你可以提供一个scoring 参数设置为 scikit-learn 模型度量(分类的默认值是'accuracy' ):

提示

使用n_jobs 参数可充分利用 CPU,加快运行速度。如果将其设置为-1 ,则会使用所有 CPU。

>>> from yellowbrick.model_selection import (
...     ValidationCurve,
... )
>>> fig, ax = plt.subplots(figsize=(6, 4))
>>> vc_viz = ValidationCurve(
...     RandomForestClassifier(n_estimators=100),
...     param_name="max_depth",
...     param_range=np.arange(1, 11),
...     cv=10,
...     n_jobs=-1,
... )
>>> vc_viz.fit(X, y)
>>> vc_viz.poof()
>>> fig.savefig("images/mlpr_1101.png", dpi=300)
Validation curve report.
图 11-1. 验证曲线报告。

ValidationCurve 类支持一个scoring 参数。该参数可以是一个自定义函数,也可以是以下选项之一,具体取决于任务。

分类scoring 选项包括'accuracy','average_precision','f1','f1_micro','f1_macro','f1_weighted','f1_samples','neg_log_loss','precision','recall', 和'roc_auc' 。

聚类scoring 选项:'adjusted_mutual_info_score','adjusted_rand_score','completeness_score' 、'fowlkesmallows_score','homogeneity_score','mutual_info_score','normalized_mutual_info_score', 和'v_measure_score' 。

回归scoring 选项 : 'explained_variance','neg_mean_absolute_error','neg_mean_squared_error','neg_mean_squared_log_error','neg_median_absolute_error', 和'r2' 。

学习曲线

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

雷达趋势观察:2025年7月

雷达趋势观察:2025年7月

Mike Loukides
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé

Publisher Resources

ISBN: 9798341663046