


'''simple docstring'''

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





def __snake_case					(      UpperCAmelCase_						:						str		):
 return 1 / (1 + np.exp(-z		))





def __snake_case					(      UpperCAmelCase_						:						Optional[Any]					,				UpperCAmelCase_						:						List[str]		):
 return (-y * np.log(__lowerCamelCase		) - (1 - y) * np.log(1 - h		)).mean()





def __snake_case					(      UpperCAmelCase_						:						Dict					,				UpperCAmelCase_						:						Dict					,				UpperCAmelCase_						:						Dict		):
 lowerCamelCase_      =  np.dot(__lowerCamelCase					,				__lowerCamelCase		)
 return np.sum(y * scores - np.log(1 + np.exp(__lowerCamelCase		)		)		)





def __snake_case					(      UpperCAmelCase_						:						List[str]					,				UpperCAmelCase_						:						List[str]					,				UpperCAmelCase_						:						Union[str, Any]					,				UpperCAmelCase_						:						str=70000		):
 lowerCamelCase_      =  np.zeros(x.shape[1]		)

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


# In[68]:

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

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





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

     plt.legend()







     plt.show()





"""simple docstring"""



from math import pow
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					__lowerCamelCase   :       int ,					)     ->					tuple[int, int]:
  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  _snake_case					     =       int(pow(__lowerCamelCase ,					__lowerCamelCase		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    _snake_case     ,					_snake_case					     =       backtrack(
        __lowerCamelCase ,					__lowerCamelCase ,					current_number + 1 ,					__lowerCamelCase ,					__lowerCamelCase		)
  return current_sum, solutions_count
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int ,					__lowerCamelCase   :       int		)     ->					int:
  if not (1 <= needed_sum <= 10_00 and 2 <= power <= 10):
    raise ValueError(
        '''Invalid input\n'''
        '''needed_sum must be between 1 and 1000, power between 2 and 10.'''		)

  return backtrack(__lowerCamelCase ,					__lowerCamelCase ,					1 ,					0 ,					0		)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()



