Back to Practice
#0012

Sigmoid Converts Scores To Probabilities

EasyML12 min10 XP

Problem

Given a NumPy array of raw scores, return the sigmoid value for each score: 1 / (1 + exp(-score)).

Why This Matters

Logistic regression and neural networks often produce raw scores first. Sigmoid explains how a score becomes a probability-like value.

Function Signature

def sigmoid(scores):

Examples

Example 1
Inputscores = np.array([0, 2, -2])
Outputarray([0.5, 0.8808, 0.1192])

A score of 0 maps to 0.5. Positive scores move toward 1; negative scores move toward 0.

Constraints

  • Input is a NumPy array of numeric scores.
  • Return a NumPy array of the same shape.
  • Do not round inside the function.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 4 hidden categories
Common score values
Inputnp.array([0, 2, -2])
Expectedapproximately [0.5, 0.8808, 0.1192]

The sigmoid curve is centered at score 0.

Hidden Test Categories
All positive scoresAll negative scores2D array inputLarge magnitude values