"""simple docstring"""





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





def 				a_     (      _lowerCAmelCase  : List[Any]     ):





       '''simple docstring'''

       return 1 / (1 + np.exp(-z     ))





def 				a_     (      _lowerCAmelCase  : str   , _lowerCAmelCase  : int     ):





       '''simple docstring'''

       return (-y * np.log(_UpperCamelCase     ) - (1 - y) * np.log(1 - h     )).mean()





def 				a_     (      _lowerCAmelCase  : str   , _lowerCAmelCase  : Optional[int]   , _lowerCAmelCase  : List[Any]     ):





       '''simple docstring'''

       lowercase__			:		List[str]       =	np.dot(_UpperCamelCase   , _UpperCamelCase     )
       return np.sum(y * scores - np.log(1 + np.exp(_UpperCamelCase     )     )     )





def 				a_     (      _lowerCAmelCase  : Union[str, Any]   , _lowerCAmelCase  : List[str]   , _lowerCAmelCase  : Union[str, Any]   , _lowerCAmelCase  : Dict=7_0000     ):





       '''simple docstring'''

       lowercase__			:		Union[str, Any]       =	np.zeros(x.shape[1]     )

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

       _UpperCamelCase   :						List[Any]      =    0.1
       _UpperCamelCase   :						Any      =    logistic_reg(alpha, x, y, max_iterations=7_00_00)
       print("theta: ", theta)  # printing the theta i.e our weights vector





       def 				a_     (      _lowerCAmelCase  : Union[str, Any]     ):





              '''simple docstring'''

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

       plt.legend()






       plt.show()




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase :      Any					 =     {
    "configuration_funnel": ["FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP", "FunnelConfig"],
    "convert_funnel_original_tf_checkpoint_to_pytorch": [],
    "tokenization_funnel": ["FunnelTokenizer"],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowerCamelCase :      Optional[Any]					 =     ["FunnelTokenizerFast"]

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowerCamelCase :      List[str]					 =     [
         "FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST",
         "FunnelBaseModel",
         "FunnelForMaskedLM",
         "FunnelForMultipleChoice",
         "FunnelForPreTraining",
         "FunnelForQuestionAnswering",
         "FunnelForSequenceClassification",
         "FunnelForTokenClassification",
         "FunnelModel",
         "FunnelPreTrainedModel",
         "load_tf_weights_in_funnel",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowerCamelCase :      Union[str, Any]					 =     [
         "TF_FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST",
         "TFFunnelBaseModel",
         "TFFunnelForMaskedLM",
         "TFFunnelForMultipleChoice",
         "TFFunnelForPreTraining",
         "TFFunnelForQuestionAnswering",
         "TFFunnelForSequenceClassification",
         "TFFunnelForTokenClassification",
         "TFFunnelModel",
         "TFFunnelPreTrainedModel",
     ]


if TYPE_CHECKING:
     from .configuration_funnel import FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP, FunnelConfig
     from .tokenization_funnel import FunnelTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_funnel_fast import FunnelTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_funnel import (
              FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST,
              FunnelBaseModel,
              FunnelForMaskedLM,
              FunnelForMultipleChoice,
              FunnelForPreTraining,
              FunnelForQuestionAnswering,
              FunnelForSequenceClassification,
              FunnelForTokenClassification,
              FunnelModel,
              FunnelPreTrainedModel,
              load_tf_weights_in_funnel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_funnel import (
              TF_FUNNEL_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFFunnelBaseModel,
              TFFunnelForMaskedLM,
              TFFunnelForMultipleChoice,
              TFFunnelForPreTraining,
              TFFunnelForQuestionAnswering,
              TFFunnelForSequenceClassification,
              TFFunnelForTokenClassification,
              TFFunnelModel,
              TFFunnelPreTrainedModel,
          )

else:
     import sys

     lowerCamelCase :      Optional[Any]					 =     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
