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






def    _snake_case					(		snake_case__ :  Optional[Any]						,   snake_case__ :  Tuple  ):
	return (-y * np.log(snake_case__  ) - (1 - y) * np.log(1 - h  )).mean()






def    _snake_case					(		snake_case__ :  Optional[int]						,   snake_case__ :  Optional[int]						,   snake_case__ :  Union[str, Any]  ):
	A     = np.dot(snake_case__						,   snake_case__  )
	return np.sum(y * scores - np.log(1 + np.exp(snake_case__  )  )  )






def    _snake_case					(		snake_case__ :  str						,   snake_case__ :  List[Any]						,   snake_case__ :  Dict						,   snake_case__ :  List[Any]=7_0000  ):
	A     = np.zeros(x.shape[1]  )

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


# In[68]:

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

		_lowercase				 =					0.1
		_lowercase				 =					logistic_reg(alpha, x, y, max_iterations=7_00_00)
		print('''theta: ''', theta)  # printing the theta i.e our weights vector






		def    _snake_case					(		snake_case__ :  Optional[int]  ):
			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''')
		((_lowercase) ,     (_lowercase))				 =					(x[:, 0].min(), x[:, 0].max())
		((_lowercase) ,     (_lowercase))				 =					(x[:, 1].min(), x[:, 1].max())
		((_lowercase) ,     (_lowercase))				 =					np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
		_lowercase				 =					np.c_[xxa.ravel(), xxa.ravel()]
		_lowercase				 =					predict_prob(grid).reshape(xxa.shape)
		plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors='''black''')

		plt.legend()


		plt.show()
'''simple docstring'''

def __UpperCamelCase( _A       :					float	,      _A       :					list[float]     ):
   '''simple docstring'''
   if discount_rate < 0:
      raise ValueError('''Discount rate cannot be negative'''     )
   if not cash_flows:
      raise ValueError('''Cash flows list cannot be empty'''     )
   UpperCAmelCase__				:					str 					=	sum(
       cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_A     )     )
   return round(_A	,      ndigits=2     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()




