
# 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				):





  """simple docstring"""
  return 1 / (1 + np.exp(-z				))


def 				a__ (				snake_case    ,       snake_case				):





  """simple docstring"""
  return (-y * np.log(snake_case				) - (1 - y) * np.log(1 - h				)).mean()


def 				a__ (				snake_case    ,       snake_case    ,       snake_case				):





  """simple docstring"""
  __SCREAMING_SNAKE_CASE	:     Optional[Any] =						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=70_000				):





  """simple docstring"""
  __SCREAMING_SNAKE_CASE	:     Union[str, Any] =						np.zeros(x.shape[1]				)

  for iterations in range(snake_case				):
    __SCREAMING_SNAKE_CASE	:     Any =						np.dot(snake_case    ,       snake_case				)
    __SCREAMING_SNAKE_CASE	:     Any =						sigmoid_function(snake_case				)
    __SCREAMING_SNAKE_CASE	:     Any =						np.dot(x.T    ,       h - y				) / y.size
    __SCREAMING_SNAKE_CASE	:     Optional[Any] =						theta - alpha * gradient  # updating the weights
    __SCREAMING_SNAKE_CASE	:     List[str] =						np.dot(snake_case    ,       snake_case				)
    __SCREAMING_SNAKE_CASE	:     List[str] =						sigmoid_function(snake_case				)
    __SCREAMING_SNAKE_CASE	:     int =						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=70_000)
   print("""theta: """, theta)  # printing the theta i.e our weights vector


   def 				a__ (				snake_case				):





     """simple docstring"""
     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_)      							=       (x[:, 0].min(), x[:, 0].max())
   (lowercase_)      							=       (x[:, 1].min(), x[:, 1].max())
   (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()

from typing import TYPE_CHECKING

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


__lowerCamelCase					:	Dict       =  {'''configuration_vit_mae''': ['''VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTMAEConfig''']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	Any       =  [
		    '''VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''ViTMAEForPreTraining''',
		    '''ViTMAELayer''',
		    '''ViTMAEModel''',
		    '''ViTMAEPreTrainedModel''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCamelCase					:	Optional[Any]       =  [
		    '''TFViTMAEForPreTraining''',
		    '''TFViTMAEModel''',
		    '''TFViTMAEPreTrainedModel''',
		]

if TYPE_CHECKING:
		from .configuration_vit_mae import VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTMAEConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_vit_mae import (
				    VIT_MAE_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ViTMAEForPreTraining,
				    ViTMAELayer,
				    ViTMAEModel,
				    ViTMAEPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_vit_mae import TFViTMAEForPreTraining, TFViTMAEModel, TFViTMAEPreTrainedModel


else:
		import sys

		__lowerCamelCase					:	Any       =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
