Skip to content
Back to skills

Rmsle Keras Metric

ASecurity

Custom Keras RMSLE metric using K.log with K.clip to safely evaluate price and count regression during training

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
developmentpythonbackend

Works with

  • cli

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill rmsle-keras-metric --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rmsle Keras Metric?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rmsle Keras Metric
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-rmsle-keras-metric/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-rmsle-keras-metric)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tabular-rmsle-keras-metric
description: Custom Keras RMSLE metric using K.log with K.clip to safely evaluate price and count regression during training
---

# RMSLE Keras Metric

## Overview

Root Mean Squared Logarithmic Error (RMSLE) penalizes under-prediction more than over-prediction, making it ideal for price, sales, or count regression. Implement it as a custom Keras metric so it displays during training alongside loss. Use `K.clip` to avoid `log(0)`.

## Quick Start

```python
from tensorflow.keras import backend as K

def rmsle(y_true, y_pred):
    first_log = K.log(K.clip(y_pred, K.epsilon(), None) + 1.)
    second_log = K.log(K.clip(y_true, K.epsilon(), None) + 1.)
    return K.sqrt(K.mean(K.square(first_log - second_log), axis=-1))

model.compile(optimizer='adam', loss='mse', metrics=['mae', rmsle])
```

## Workflow

1. Define `rmsle` as a function of `(y_true, y_pred)` using Keras backend ops
2. Clip predictions to `[epsilon, inf)` before log to prevent NaN
3. Add 1 before log (log1p) to handle zero values
4. Pass as `metrics=[rmsle]` in `model.compile`
5. Monitor during training — it tracks the competition metric directly

## Key Decisions

- **Clip vs relu**: `K.clip` is safer — relu zeros out negatives silently
- **Loss vs metric**: use MSE or MAE as loss (smoother gradients), RMSLE as metric
- **Log1p target**: if target is already log-transformed, use RMSE instead of RMSLE
- **vs sklearn**: `sklearn.metrics.mean_squared_log_error` works for evaluation only, not as a Keras metric

## References

- [A simple nn solution with Keras](https://www.kaggle.com/code/knowledgegrappler/a-simple-nn-solution-with-keras-0-48611-pl)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…