






'''simple docstring'''

import numpy as np
from matplotlib import pyplot as plt
from sklearn import datasets







def 					lowercase__				(   __UpperCamelCase					)->				str:
      return 1 / (1 + np.exp(-z					))







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase					)->				List[Any]:
      return (-y * np.log(__UpperCamelCase					) - (1 - y) * np.log(1 - h					)).mean()







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				List[Any]:
      UpperCamelCase       						=      np.dot(__UpperCamelCase	,		__UpperCamelCase					)
      return np.sum(y * scores - np.log(1 + np.exp(__UpperCamelCase					)					)					)







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase=70000					)->				List[Any]:
      UpperCamelCase       						=      np.zeros(x.shape[1]					)

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


# In[68]:

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

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







     def 					lowercase__				(   __UpperCamelCase					)->				str:
           return sigmoid_function(
               np.dot(__UpperCamelCase	,		__UpperCamelCase					)					)  # predicting the value of probability from the logistic regression algorithm

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

     plt.legend()






     plt.show()







'''simple docstring'''

SCREAMING_SNAKE_CASE__											=     8.31_44_62  # Unit - J mol-1 K-1







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				float:
      if moles < 0 or kelvin < 0 or volume < 0:
            raise ValueError("""Invalid inputs. Enter positive value."""					)
      return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				float:
      if moles < 0 or kelvin < 0 or pressure < 0:
            raise ValueError("""Invalid inputs. Enter positive value."""					)
      return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure


if __name__ == "__main__":
     from doctest import testmod

     testmod()
