我试图在删除之前使用Keras提供的代码.这是代码:
def precision(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def recall(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def fbeta_score(y_true, y_pred, beta=1):
if beta < 0:
raise ValueError('The lowest choosable beta is zero (only precision).')
# If there are no true positives, fix the F score at 0 like …Run Code Online (Sandbox Code Playgroud) 我目前正在使用这个代码,我从github 上的一个讨论得到这里是注意机制的代码:
_input = Input(shape=[max_length], dtype='int32')
# get the embedding layer
embedded = Embedding(
input_dim=vocab_size,
output_dim=embedding_size,
input_length=max_length,
trainable=False,
mask_zero=False
)(_input)
activations = LSTM(units, return_sequences=True)(embedded)
# compute importance for each step
attention = Dense(1, activation='tanh')(activations)
attention = Flatten()(attention)
attention = Activation('softmax')(attention)
attention = RepeatVector(units)(attention)
attention = Permute([2, 1])(attention)
sent_representation = merge([activations, attention], mode='mul')
sent_representation = Lambda(lambda xin: K.sum(xin, axis=-2), output_shape=(units,))(sent_representation)
probabilities = Dense(3, activation='softmax')(sent_representation)
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?我有点期待时间分布层的存在,因为注意机制分布在RNN的每个时间步骤中.我需要有人确认这个实现(代码)是一个正确的注意机制实现.谢谢.
我目前正在进行多类分类的研究.我使用了分类交叉熵,并且我使用准确度作为实验的指标得到了非常好的结果.当我尝试使用categorical_accuracy时,它会给出稍差的准确度(低于1%).我的问题是,是否可以使用准确度指标来进行分类的交叉熵损失,而不是使用categorical_accuracy?
我尝试使用H2O为二分类问题创建了一些机器学习模型,测试结果相当不错。但后来我检查并发现了一些奇怪的东西。出于好奇,我试图打印模型对测试集的预测。而且我发现我的模型实际上一直在预测 0(负),但是 AUC 在 0.65 左右,精度不是 0.0。然后我尝试使用 Scikit-learn 来比较指标分数,并且(正如预期的那样)它们是不同的。Scikit 学习产生了 0.0 精度和 0.5 AUC 分数,我认为这是正确的。这是我使用的代码:
model = h2o.load_model(model_path)
predictions = model.predict(Test_data).as_data_frame()
# H2O version to print the AUC score
auc = model.model_performance(Test_data).auc()
# Python version to print the AUC score
auc_sklearn = sklearn.metrics.roc_auc_score(y_true, predictions['predict'].tolist())
Run Code Online (Sandbox Code Playgroud)
任何想法?提前致谢!
我在实现我在论文中看到的交叉验证设置时遇到了一些麻烦。基本上它在这张附图中进行了解释:

所以,它说他们使用 5 折,这意味着k = 5. 但是随后,作者说他们重复了 20 次交叉验证,总共产生了 100 次折叠。这是否意味着我可以只使用这段代码:
kfold = StratifiedKFold(n_splits=100, shuffle=True, random_state=seed)
Run Code Online (Sandbox Code Playgroud)
因为基本上我的代码也产生了 100 倍。有什么推荐吗?
使用dcc.Upload,您可以在 Dash Plotly 仪表板中构建拖放或基于按钮的上传功能。但是,文档中对处理特定文件类型(例如.zip. 这是上传 html 的片段:
dcc.Upload(\n id=\'upload_prediction\',\n children=html.Div([\n \'Drag and Drop or \',\n html.A(\'Select Files\'),\n \' New Predictions (*.zip)\'\n ]),\n style={\n \'width\': \'100%\',\n \'height\': \'60px\',\n \'lineHeight\': \'60px\',\n \'borderWidth\': \'1px\',\n \'borderStyle\': \'dashed\',\n \'borderRadius\': \'5px\',\n \'textAlign\': \'center\',\n \'margin\': \'10px\'\n },\n accept=".zip",\n multiple=True\n)\nRun Code Online (Sandbox Code Playgroud)\n\n然后,当我尝试使用以下代码片段检查上传的文件时:
\n\n@app.callback(Output(\'output_uploaded\', \'children\'),\n [Input(\'upload_prediction\', \'contents\')],\n [State(\'upload_prediction\', \'filename\'),\n State(\'upload_prediction\', \'last_modified\')])\ndef test_callback(list_of_contents, list_of_names, list_of_dates):\n for content in list_of_contents:\n print(content)\nRun Code Online (Sandbox Code Playgroud)\n\n上传后的content-type为\xe2\x80\x98data:application/x-zip-compressed;base64\xe2\x80\x99。如何在 Dash Plotly 中处理这种类型的文件(例如将其提取到某个地方)?
\n\n在plotly论坛中提出了类似的问题,但没有答案:\n https://community.plot.ly/t/dcc-upload-zip-file/33976
\n