




from __future__ import annotations



class        UpperCamelCase_					:

    '''simple docstring'''






    def __init__(    self   :			Union[str, Any]      ,				UpperCAmelCase__   :			int)		->None:





           '''simple docstring'''

           A__   				=					data
           A__   				=					None
           A__   				=					None







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> None:  # In Order traversal of the tree



       """simple docstring"""

       if tree:
              display(tree.left		)
              print(tree.data		)
              display(tree.right		)







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> int:



       """simple docstring"""

       return 1 + max(depth_of_tree(tree.left		)				,       depth_of_tree(tree.right		)		) if tree else 0







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> bool:



       """simple docstring"""

       if not tree:
              return True
       if tree.left and tree.right:
              return is_full_binary_tree(tree.left		) and is_full_binary_tree(tree.right		)
       else:
              return not tree.left and not tree.right







def SCREAMING_SNAKE_CASE       ( )     -> None:  # Main function for testing.



       """simple docstring"""

       A__   				=					Node(1		)
       A__   				=					Node(2		)
       A__   				=					Node(3		)
       A__   				=					Node(4		)
       A__   				=					Node(5		)
       A__   				=					Node(6		)
       A__   				=					Node(7		)
       A__   				=					Node(8		)
       A__   				=					Node(9		)

       print(is_full_binary_tree(lowercase_		)		)
       print(depth_of_tree(lowercase_		)		)
       print('''Tree is: '''		)
       display(lowercase_		)


if __name__ == "__main__":
  main()








# 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()


