




from collections import deque







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					len(_lowerCamelCase		)
       A__   				=					deque()
       A__   				=					[False for _ in range(_lowerCamelCase		)]
       A__   				=					[-1 for _ in range(_lowerCamelCase		)]
       A__   				=					index_of[:]

       def strong_connect(lowercase_				,       lowercase_				,       lowercase_		):
              A__   				=					index  # the number when this node is seen
              A__   				=					index  # lowest rank node reachable from here
              index += 1
              stack.append(_lowerCamelCase		)
              A__   				=					True

              for w in g[v]:
                     if index_of[w] == -1:
                            A__   				=					strong_connect(_lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase		)
                            A__   				=					(
                                lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                            )
                     elif on_stack[w]:
                            A__   				=					(
                                lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                            )

              if lowlink_of[v] == index_of[v]:
                     A__   				=					[]
                     A__   				=					stack.pop()
                     A__   				=					False
                     component.append(_lowerCamelCase		)
                     while w != v:
                            A__   				=					stack.pop()
                            A__   				=					False
                            component.append(_lowerCamelCase		)
                     components.append(_lowerCamelCase		)
              return index

       A__   				=					[]
       for v in range(_lowerCamelCase		):
              if index_of[v] == -1:
                     strong_connect(_lowerCamelCase				,       0				,       _lowerCamelCase		)

       return components







def SCREAMING_SNAKE_CASE       ( lowercase_				,       lowercase_		)     -> Dict:



       """simple docstring"""

       A__   				=					[[] for _ in range(_lowerCamelCase		)]
       for u, v in edges:
              g[u].append(_lowerCamelCase		)
       return g


if __name__ == "__main__":
  # Test
  _lowerCamelCase			:	List[Any]							 =     7
  _lowerCamelCase			:	int							 =     [0, 0, 1, 2, 3, 3, 4, 4, 6]
  _lowerCamelCase			:	Optional[Any]							 =     [1, 3, 2, 0, 1, 4, 5, 6, 5]
  _lowerCamelCase			:	int							 =     [(u, v) for u, v in zip(source, target)]
  _lowerCamelCase			:	Union[str, Any]							 =     create_graph(n_vertices, edges)

  assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)








# 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 SCREAMING_SNAKE_CASE       ( lowercase_		)     -> Dict:



       """simple docstring"""

       return 1 / (1 + np.exp(-z		))







def SCREAMING_SNAKE_CASE       ( lowercase_				,       lowercase_		)     -> Optional[int]:



       """simple docstring"""

       return (-y * np.log(lowercase_		) - (1 - y) * np.log(1 - h		)).mean()







def SCREAMING_SNAKE_CASE       ( lowercase_				,       lowercase_				,       lowercase_		)     -> int:



       """simple docstring"""

       A__   				=					np.dot(lowercase_				,       lowercase_		)
       return np.sum(y * scores - np.log(1 + np.exp(lowercase_		)		)		)







def SCREAMING_SNAKE_CASE       ( lowercase_				,       lowercase_				,       lowercase_				,       lowercase_=70_000		)     -> Dict:



       """simple docstring"""

       A__   				=					np.zeros(x.shape[1]		)

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


# In[68]:

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

  _lowerCamelCase			:	Union[str, Any]							 =     0.1
  _lowerCamelCase			:	Tuple							 =     logistic_reg(alpha, x, y, max_iterations=70000)
  print("""theta: """, theta)  # printing the theta i.e our weights vector







  def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> List[Any]:



         """simple docstring"""

         return sigmoid_function(
             np.dot(lowercase_				,       lowercase_		)		)  # 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""")
  ((_lowerCamelCase) ,    (_lowerCamelCase))			:	int							 =     (x[:, 0].min(), x[:, 0].max())
  ((_lowerCamelCase) ,    (_lowerCamelCase))			:	Union[str, Any]							 =     (x[:, 1].min(), x[:, 1].max())
  ((_lowerCamelCase) ,    (_lowerCamelCase))			:	List[Any]							 =     np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
  _lowerCamelCase			:	str							 =     np.c_[xxa.ravel(), xxa.ravel()]
  _lowerCamelCase			:	Tuple							 =     predict_prob(grid).reshape(xxa.shape)
  plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors="""black""")

  plt.legend()
  plt.show()


