MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / sigmoid_function

Function sigmoid_function

machine_learning/logistic_regression.py:31–63  ·  view source on GitHub ↗

Also known as Logistic Function. 1 f(x) = ------- 1 + e⁻ˣ The sigmoid function approaches a value of 1 as its input 'x' becomes increasing positive. Opposite for negative values. Reference: https://en.wikipedia.org/wiki/Sigmoid_function @p

(z: float | np.ndarray)

Source from the content-addressed store, hash-verified

29
30
31def sigmoid_function(z: float | np.ndarray) -> float | np.ndarray:
32 """
33 Also known as Logistic Function.
34
35 1
36 f(x) = -------
37 1 + e⁻ˣ
38
39 The sigmoid function approaches a value of 1 as its input 'x' becomes
40 increasing positive. Opposite for negative values.
41
42 Reference: https://en.wikipedia.org/wiki/Sigmoid_function
43
44 @param z: input to the function
45 @returns: returns value in the range 0 to 1
46
47 Examples:
48 >>> float(sigmoid_function(4))
49 0.9820137900379085
50 >>> sigmoid_function(np.array([-3, 3]))
51 array([0.04742587, 0.95257413])
52 >>> sigmoid_function(np.array([-3, 3, 1]))
53 array([0.04742587, 0.95257413, 0.73105858])
54 >>> sigmoid_function(np.array([-0.01, -2, -1.9]))
55 array([0.49750002, 0.11920292, 0.13010847])
56 >>> sigmoid_function(np.array([-1.3, 5.3, 12]))
57 array([0.21416502, 0.9950332 , 0.99999386])
58 >>> sigmoid_function(np.array([0.01, 0.02, 4.1]))
59 array([0.50249998, 0.50499983, 0.9836975 ])
60 >>> sigmoid_function(np.array([0.8]))
61 array([0.68997448])
62 """
63 return 1 / (1 + np.exp(-z))
64
65
66def cost_function(h: np.ndarray, y: np.ndarray) -> float:

Callers 2

logistic_regFunction · 0.70
predict_probFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected