
from __future__ import annotations

# This is the precision for this function which can be altered.
# It is recommended for users to keep this number greater than or equal to 10.
lowerCamelCase__          =		10
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		int:
			for i in range(__lowerCamelCase       ,							__lowerCamelCase     ):
						if array[i] == target:
									return i
			return -1
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		int:
			lowerCAmelCase__      :      int         =		0
			lowerCAmelCase__      :      Dict         =		len(__lowerCamelCase     )
			while left <= right:
						if right - left < precision:
									return lin_search(__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase     )

						lowerCAmelCase__      :      Tuple         =		(left + right) // 3 + 1
						lowerCAmelCase__      :      List[str]         =		2 * (left + right) // 3 + 1

						if array[one_third] == target:
									return one_third
						elif array[two_third] == target:
									return two_third

						elif target < array[one_third]:
									lowerCAmelCase__      :      List[str]         =		one_third - 1
						elif array[two_third] < target:
									lowerCAmelCase__      :      Union[str, Any]         =		two_third + 1

						else:
									lowerCAmelCase__      :      Dict         =		one_third + 1
									lowerCAmelCase__      :      str         =		two_third - 1
			else:
						return -1
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		int:
			if left < right:
						if right - left < precision:
									return lin_search(__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase     )
						lowerCAmelCase__      :      Any         =		(left + right) // 3 + 1
						lowerCAmelCase__      :      Optional[Any]         =		2 * (left + right) // 3 + 1

						if array[one_third] == target:
									return one_third
						elif array[two_third] == target:
									return two_third

						elif target < array[one_third]:
									return rec_ternary_search(__lowerCamelCase       ,							one_third - 1       ,							__lowerCamelCase       ,							__lowerCamelCase     )
						elif array[two_third] < target:
									return rec_ternary_search(two_third + 1       ,							__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase     )
						else:
									return rec_ternary_search(one_third + 1       ,							two_third - 1       ,							__lowerCamelCase       ,							__lowerCamelCase     )
			else:
						return -1


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					lowerCamelCase__          =		input("""Enter numbers separated by comma:\n""").strip()
					lowerCamelCase__          =		[int(item.strip()) for item in user_input.split(""",""")]
					assert collection == sorted(collection), F"List must be ordered.\n{collection}."
					lowerCamelCase__          =		int(input("""Enter the number to be found in the list:\n""").strip())
					lowerCamelCase__          =		ite_ternary_search(collection, target)
					lowerCamelCase__          =		rec_ternary_search(0, len(collection) - 1, collection, target)
					if resulta != -1:
										print(F"""Iterative search: {target} found at positions: {resulta}""")
										print(F"""Recursive search: {target} found at positions: {resulta}""")
					else:
										print("""Not found""")

"""simple docstring"""



# Logistic Regression from scratch

# In[62]:

# In[63]:

# importing all the required libraries

import numpy as np
from matplotlib import pyplot as plt
from sklearn import datasets
def 					_UpperCAmelCase      ( __lowerCamelCase   :       str		)     ->					List[Any]:
  return 1 / (1 + np.exp(-z		))
def 					_UpperCAmelCase      ( __lowerCamelCase   :       Optional[Any] ,					__lowerCamelCase   :       List[str]		)     ->					Optional[Any]:
  return (-y * np.log(__lowerCamelCase		) - (1 - y) * np.log(1 - h		)).mean()
def 					_UpperCAmelCase      ( __lowerCamelCase   :       Dict ,					__lowerCamelCase   :       Dict ,					__lowerCamelCase   :       Dict		)     ->					List[str]:
  _snake_case					     =       np.dot(__lowerCamelCase ,					__lowerCamelCase		)
  return np.sum(y * scores - np.log(1 + np.exp(__lowerCamelCase		)		)		)
def 					_UpperCAmelCase      ( __lowerCamelCase   :       List[str] ,					__lowerCamelCase   :       List[str] ,					__lowerCamelCase   :       Union[str, Any] ,					__lowerCamelCase   :       str=7_00_00		)     ->					Optional[Any]:
  _snake_case					     =       np.zeros(x.shape[1]		)

  for iterations in range(__lowerCamelCase		):
    _snake_case					     =       np.dot(__lowerCamelCase ,					__lowerCamelCase		)
    _snake_case					     =       sigmoid_function(__lowerCamelCase		)
    _snake_case					     =       np.dot(x.T ,					h - y		) / y.size
    _snake_case					     =       theta - alpha * gradient  # updating the weights
    _snake_case					     =       np.dot(__lowerCamelCase ,					__lowerCamelCase		)
    _snake_case					     =       sigmoid_function(__lowerCamelCase		)
    _snake_case					     =       cost_function(__lowerCamelCase ,					__lowerCamelCase		)
    if iterations % 1_00 == 0:
      print(f'''loss: {j} \t'''		)  # printing the loss after every 100 iterations
  return theta


# In[68]:

if __name__ == "__main__":
 UpperCAmelCase__          = datasets.load_iris()
 UpperCAmelCase__          = iris.data[:, :2]
 UpperCAmelCase__          = (iris.target != 0) * 1

 UpperCAmelCase__          = 0.1
 UpperCAmelCase__          = logistic_reg(alpha, x, y, max_iterations=70000)
 print('theta: ', theta)  # printing the theta i.e our weights vector
 def 					_UpperCAmelCase      ( __lowerCamelCase   :       Tuple		)     ->					Union[str, Any]:
   return sigmoid_function(
       np.dot(__lowerCamelCase ,					__lowerCamelCase		)		)  # predicting the value of probability from the logistic regression algorithm

 plt.figure(figsize=(10, 6))
 plt.scatter(x[y == 0][:, 0], x[y == 0][:, 1], color='b', label='0')
 plt.scatter(x[y == 1][:, 0], x[y == 1][:, 1], color='r', label='1')
 ((UpperCAmelCase__)      ,	(UpperCAmelCase__))          = (x[:, 0].min(), x[:, 0].max())
 ((UpperCAmelCase__)      ,	(UpperCAmelCase__))          = (x[:, 1].min(), x[:, 1].max())
 ((UpperCAmelCase__)      ,	(UpperCAmelCase__))          = np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
 UpperCAmelCase__          = np.c_[xxa.ravel(), xxa.ravel()]
 UpperCAmelCase__          = predict_prob(grid).reshape(xxa.shape)
 plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors='black')

 plt.legend()

 plt.show()



