Skip to Main Content
机器学习设计模式
book

机器学习设计模式

by Valliappa Lakshmanan, Sara Robinson, Michael Munn
September 2022
Beginner to intermediate content levelBeginner to intermediate
386 pages
7h 36m
Chinese
Southeast University Press
Content preview from 机器学习设计模式
问题表示设计模式
129
num_minority_examples = 1
num_majority_examples = 999
total_examples = num_minority_examples + num_majority_examples
minority_class_weight = 1/(num_minority_examples/total_examples)/2
majority_class_weight = 1/(num_majority_examples/total_examples)/2
#
将权值以字典的形式传回
Keras
#
键是每个类别的索引
keras_class_weights = {0: majority_class_weight, 1: minority_class_weight}
然后在训练期间将这些权值传递给我们的模型:
model.fit(
train_data,
train_labels,
class_weight=keras_class_weights
)
BigQuery ML
中,当创建模型时,我们可以在
OPTIONS
块中设置
AUTO_CLASS_
WEIGHTS = True
,以根据它们在训练数据中出现的频率对不同的类别进行加权。
遵循启发式的类别平衡来设置权值是有帮助的,而模型的业务应用也可以指导我们
选择和分配类别的权值。例如,假设我们有一个对有缺陷产品的图像进行分类的模型。
如果一个有缺陷产品的运费是那些被错误分类的正常产品的 ...
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.
Start your free trial

You might also like

PyTorch深度学习

PyTorch深度学习

Posts & Telecom Press, Vishnu Subramanian
数据科学原理

数据科学原理

Posts & Telecom Press, Sinan Ozdemir
Rust程序设计

Rust程序设计

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall

Publisher Resources

ISBN: 9787564196776