我已经在许多kaggle笔记本电脑中看到,人们在使用K-fold验证进行机器学习时都在谈论oof方法。什么是oof,它与k倍验证有关?您还可以建议一些有用的资源来详细了解概念吗
感谢您的帮助!
我正在尝试在 keras 中进行多类分类。到目前为止,我使用 categorical_crossentropy 作为损失函数。但由于所需的指标是weighted-f1,我不确定categorical_crossentropy是否是最佳损失选择。我试图使用sklearn.metrics.f1_score在 keras 中实现加权 f1 分数,但由于张量和标量之间的转换问题,我遇到了错误。
像这样的东西:
def f1_loss(y_true, y_pred):
return 1 - f1_score(np.argmax(y_true, axis=1), np.argmax(y_pred, axis=1), average='weighted')
Run Code Online (Sandbox Code Playgroud)
其次是
model.compile(loss=f1_loss, optimizer=opt)
Run Code Online (Sandbox Code Playgroud)
我如何在 keras 中编写这个损失函数?
编辑:
y_true 和 y_pred 的形状是(n_samples, n_classes)在我的情况下是(n_samples, 4)
y_true和y_pred都是张量,所以 sklearn 的 f1_score 不能直接对它们起作用。我需要一个函数来计算 tensors 上的加权 f1。
我想安装腹地以在 google colab 中使用。我按照官方页面上的安装说明进行操作
基本上我做了以下步骤:
!pip install https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tarball/master
!jupyter contrib nbextension install --user
Run Code Online (Sandbox Code Playgroud)
现在,当我想启用任何特定扩展名时说“腹地”,我执行以下操作:
!jupyter nbextension enable /usr/local/lib/python3.6/dist-packages/jupyter_contrib_nbextensions/nbextensions/hinterland/hinterland.js
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误说:
Enabling notebook extension /usr/local/lib/python3.6/dist-packages/jupyter_contrib_nbextensions/nbextensions/hinterland/hinterland.js...
- Validating: problems found:
- require? X /usr/local/lib/python3.6/dist-packages/jupyter_contrib_nbextensions/nbextensions/hinterland/hinterland.js
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我在任何一步都出错了吗?
或者有没有其他更好的方法来专门为 google colab 安装这些扩展。
例如,如果我的训练数据在col中具有分类值(1,2,3,4,5),那么一种热编码将给我5 col。但是在测试数据中,我说的只有5个值中的4个,即(1,3,4,5)。因此,一次热编码只会给我4个cols。因此,如果我将训练有素的权重应用于测试数据,我会得到一个错误,因为在训练和测试数据中cols的尺寸不匹配dim(4)!= dim(5)。关于如何处理丢失的col值的任何建议?下面提供了我的代码的图像:
我正在尝试在Google colab笔记本中安装OpenCV。官方文件说:
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
Run Code Online (Sandbox Code Playgroud)
第一条语句可以正常运行并安装所有内容。但是在导入cv2时出现错误提示:
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这个问题有解决办法吗?感谢帮助!
我在做图像分类.首先,我将我的图像提供给我在Keras的CNN模型.
我想在keras的Flatten图层的输出处添加新功能,然后将其提供给密集层.我该如何为它编写代码?
基本上我使用Convolution图像,然后最后我想添加其他功能,如Age Sex等.
max_pool_final = MaxPooling2D(pool_size=(2,2))(conv_final)
flat = Flatten()(max_pool_final)
dense = Dense(128)(flat)
Run Code Online (Sandbox Code Playgroud)
在作为密集层的输入进行平坦馈送之前,我想添加一些功能到平面.我该怎么做呢?
感谢帮助!
我有一个基本问题。据说我正在训练猫和狗的图像分类器。但我需要一个额外的功能。如果图像不属于任何类别,我如何才能知道它。我想到的一些选择是:
但我认为任何方法都不可行。
谁能建议我一种好的技术来对不属于我的训练类别的图像进行分类?
classification machine-learning neural-network deep-learning keras
SELECT customerid,
(SELECT COUNT(*)
FROM orders
WHERE customers.customerid = orders.customerid) as total_orders
FROM customers
Run Code Online (Sandbox Code Playgroud)
谁能解释一下这段 SQL 代码的工作原理吗?根据我的说法,在这种情况下子查询应该始终返回相同的行数,因为总行数。相同的行
customers.customerid = orders.customerid。但它显示每个客户以及他/她的订单总数。导致此结果的执行顺序是什么?
请在此处查找数据库:
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_distinct
keras ×3
kaggle ×1
keras-layer ×1
numpy ×1
opencv ×1
pandas ×1
python-3.x ×1
scikit-learn ×1
sql ×1
tensorflow ×1