---
id: "5839394e-59fb-4edf-8d15-b11a4cb09436"
name: asymmetric-cost-loss-function-false-negative-cost-0-aa3048d949ce
description: "Defines a custom loss function in TensorFlow/Keras where predicting 1 as 0 (False Negative) has zero cost, while predicting 0 as 1 (False Positive) has a cost of 1."
version: "0.1.0"
tags:
  - "tensorflow"
  - "keras"
  - "loss function"
  - "asymmetric cost"
  - "imbalanced data"
  - "machine learning"
triggers:
  - "自定义一个评估标准，把1预测成0不算错"
  - "自定义loss函数"
  - "把1预测成0不算错"
---

# Asymmetric Cost Loss Function (False Negative Cost = 0)

Defines a custom loss function in TensorFlow/Keras where predicting 1 as 0 (False Negative) has zero cost, while predicting 0 as 1 (False Positive) has a cost of 1.

## Prompt

Define a custom loss function in TensorFlow/Keras. The loss function must implement the logic where the cost of False Negatives (predicting 1 as 0) is 0. The cost of False Positives (predicting 0 as 1) is 1. Ensure type casting to float32 to avoid type mismatch errors.

## Triggers

- 自定义一个评估标准，把1预测成0不算错
- 自定义loss函数
- 把1预测成0不算错


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering
Roles: Data Analyst, Data Scientist, ML / AI Engineer
Specialties: API
Tools: Keras, Tensorflow
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: ea3b881119706dbdca4a550ba3b4e93201ba7f0b8225bdfa445133c8ab7ff659
