Skip to Content
机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)
book

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

by Aurélien Géron
October 2020
Intermediate to advanced
693 pages
16h 26m
Chinese
China Machine Press
Content preview from 机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)
272
10
使用模型进行预测
接下来,我们可以使用模型的 predict() 方法对新实例进行预测。由于没有实际的新
实例,因此我们将仅使用测试集的前三个实例:
>>>
X_new = X_test[:3]
>>>
y_proba = model.predict(X_new)
>>>
y_proba.round(2)
array([[0. , 0. , 0. , 0. , 0. , 0.03, 0. , 0.01, 0. , 0.96],
[0. , 0. , 0.98, 0. , 0.02, 0. , 0. , 0. , 0. , 0. ],
[0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ]],
dtype=float32)
如你所见,对于每个实例,模型估计从 0 类到 9 类每个类的概率。例如,对于第一个图
像,模型估计是第 9 类(脚踝靴)的概率为 96%,第 5 类的概率(凉鞋)为 3%,第 7
类(运动鞋)的概率为 1%,其他类别的概率可忽略不计。换句话说,它“相信”第一
个图像是鞋类,最有可能是脚踝靴,但也可能是凉鞋或运动鞋。如果你只关心估计概率
最高的类(即使该概率非常低),则可以使用 pre dict_classes() 方法:
>>>
y_pred = model.predict_classes(X_new)
>>>
y_pred
array([9, 2, 1])
>>>
np.array(class_names)[y_pred] ...
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

算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow
Go语言编程

Go语言编程

威廉·肯尼迪
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787111665977