python - 如何使用 tensorflow 模型从 h5 中获得预测
问题描述
所以我无法弄清楚如何从这个矩阵中获得百分比或标签的概率。
这个模型背后的故事:
- 该模型应该检测是否应该删除评论(/文本)。
-标签是真或假
有什么方法可以让它工作或者我可以如何转换那个向量?
我的代码:
model = models.load_model(h5_model)
string = "sh!t"
x_test = string.lower()
tok = text.Tokenizer(num_words=max_features, lower=True)
tok.fit_on_texts(list(x_test))
x_test = tok.texts_to_sequences(x_test)
text_preprocessing_for_single_comments(string)
prediction = model.predict(to_predict)
print(prediction)
>>[[0.5180945 ][0.5354299 ][0.47555092] [0.5636673]]
解决方案
预测是类概率。对于百分比转换:
prediction *= 100
如果 1 表示真,0 表示假,那么高于 0.5 的概率表示真,低于 0.5 的概率表示假。
prediction = np.round( prediction )
# Get an array of 0s and 1s
class = np.argmax( prediction )
推荐阅读
- javascript - 谷歌地图标记在 React 中没有刷新
- jquery - 未调用 JQuery getJSON 方法
- python - 在 for 循环中调用 Python 变量
- clojure - 一个 cond-> 线程宏替代方案,它引用谓词中的最后一个线程状态?
- html - HTML | CSS:汉堡菜单的问题
- informix - 松鼠找不到informix驱动
- r - 编写一个包含日期范围的循环
- ios - 如何在 Flutter 中隐藏导航栏(在 iPhone X 上)
- android - 如何创建类似于新的 youtube UI 的可展开和可折叠的片段?
- javascript - 在日期选择器 js 中禁用时间