


"""simple docstring"""






class      A:

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__=None   )      ->	int:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	data
					_UpperCamelCase					:Any					     =	previous
					_UpperCamelCase					:List[str]					     =	next_node
		def __str__( self   )      ->	str:

					"""simple docstring"""



					return f"{self.data}"
		def   _UpperCamelCase( self   )      ->	int:

					"""simple docstring"""



					return self.data
		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



					return self.next





		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					return self.previous






class      A:

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__   )      ->	Optional[Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[str]					     =	head
		def __iter__( self   )      ->	List[str]:

					"""simple docstring"""



					return self





		def   _UpperCamelCase( self   )      ->	Any:

					"""simple docstring"""



					if not self.current:
								raise StopIteration
					else:
								_UpperCamelCase					:str					     =	self.current.get_data()
								_UpperCamelCase					:List[Any]					     =	self.current.get_next()
								return value






class      A:

		"""simple docstring"""





		def __init__( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	None  # First node in list
					_UpperCamelCase					:List[str]					     =	None  # Last node in list
		def __str__( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	self.head
					_UpperCamelCase					:Any					     =	[]
					while current is not None:
								nodes.append(current.get_data()   )
								_UpperCamelCase					:str					     =	current.get_next()
					return " ".join(str(SCREAMING_SNAKE_CASE__   ) for node in nodes   )
		def __contains__( self					,				SCREAMING_SNAKE_CASE__   )      ->	Any:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.head
					while current:
								if current.get_data() == value:
											return True
								_UpperCamelCase					:Tuple					     =	current.get_next()
					return False
		def __iter__( self   )      ->	Dict:

					"""simple docstring"""



					return LinkedListIterator(self.head   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					if self.head:
								return self.head.get_data()
					return None
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



					if self.tail:
								return self.tail.get_data()
					return None
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					if self.head is None:
								_UpperCamelCase					:List[str]					     =	node
								_UpperCamelCase					:List[Any]					     =	node
					else:
								self.insert_before_node(self.head					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					if self.head is None:
								self.set_head(SCREAMING_SNAKE_CASE__   )
					else:
								self.insert_after_node(self.tail					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	Node(SCREAMING_SNAKE_CASE__   )
					if self.head is None:
								self.set_head(SCREAMING_SNAKE_CASE__   )
					else:
								self.set_tail(SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	node
					_UpperCamelCase					:Tuple					     =	node.previous

					if node.get_previous() is None:
								_UpperCamelCase					:str					     =	node_to_insert
					else:
								_UpperCamelCase					:Dict					     =	node_to_insert

					_UpperCamelCase					:Any					     =	node_to_insert
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	node
					_UpperCamelCase					:Tuple					     =	node.next

					if node.get_next() is None:
								_UpperCamelCase					:Dict					     =	node_to_insert
					else:
								_UpperCamelCase					:List[str]					     =	node_to_insert

					_UpperCamelCase					:str					     =	node_to_insert
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	1
					_UpperCamelCase					:Dict					     =	Node(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:List[Any]					     =	self.head
					while node:
								if current_position == position:
											self.insert_before_node(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
											return
								current_position += 1
								_UpperCamelCase					:Dict					     =	node.next
					self.insert_after_node(self.tail					,				SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	Node:

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	self.head
					while node:
								if node.get_data() == item:
											return node
								_UpperCamelCase					:str					     =	node.get_next()
					raise Exception('''Node not found'''   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	Any:

					"""simple docstring"""



					if (node := self.get_node(SCREAMING_SNAKE_CASE__   )) is not None:
								if node == self.head:
											_UpperCamelCase					:Union[str, Any]					     =	self.head.get_next()

								if node == self.tail:
											_UpperCamelCase					:str					     =	self.tail.get_previous()

								self.remove_node_pointers(SCREAMING_SNAKE_CASE__   )
		@staticmethod
		def   _UpperCamelCase( SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					if node.get_next():
								_UpperCamelCase					:List[str]					     =	node.previous

					if node.get_previous():
								_UpperCamelCase					:Union[str, Any]					     =	node.next

					_UpperCamelCase					:Dict					     =	None
					_UpperCamelCase					:Tuple					     =	None





		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					return self.head is None





def 				A_       ( )					->  None:
			pass


if __name__ == "__main__":
					import doctest

					doctest.testmod()





"""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 				A_       ( snake_case__		)					->  str:
			return 1 / (1 + np.exp(-z		))





def 				A_       ( snake_case__       ,					snake_case__		)					->  str:
			return (-y * np.log(snake_case__		) - (1 - y) * np.log(1 - h		)).mean()





def 				A_       ( snake_case__       ,					snake_case__       ,					snake_case__		)					->  Union[str, Any]:
			_UpperCamelCase					:Tuple					     =	np.dot(snake_case__       ,					snake_case__		)
			return np.sum(y * scores - np.log(1 + np.exp(snake_case__		)		)		)





def 				A_       ( snake_case__       ,					snake_case__       ,					snake_case__       ,					snake_case__=7_00_00		)					->  Optional[int]:
			_UpperCamelCase					:Union[str, Any]					     =	np.zeros(x.shape[1]		)

			for iterations in range(snake_case__		):
						_UpperCamelCase					:Optional[int]					     =	np.dot(snake_case__       ,					snake_case__		)
						_UpperCamelCase					:Tuple					     =	sigmoid_function(snake_case__		)
						_UpperCamelCase					:Optional[Any]					     =	np.dot(x.T       ,					h - y		) / y.size
						_UpperCamelCase					:int					     =	theta - alpha * gradient  # updating the weights
						_UpperCamelCase					:Union[str, Any]					     =	np.dot(snake_case__       ,					snake_case__		)
						_UpperCamelCase					:Dict					     =	sigmoid_function(snake_case__		)
						_UpperCamelCase					:Optional[int]					     =	cost_function(snake_case__       ,					snake_case__		)
						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__				:Union[str, Any]			   =	datasets.load_iris()
					UpperCamelCase__				:Dict			   =	iris.data[:, :2]
					UpperCamelCase__				:Any			   =	(iris.target != 0) * 1

					UpperCamelCase__				:Tuple			   =	0.1
					UpperCamelCase__				:List[str]			   =	logistic_reg(alpha, x, y, max_iterations=70_000)
					print("""theta: """, theta)  # printing the theta i.e our weights vector





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

					plt.legend()




					plt.show()

