





# 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      lowerCAmelCase_ (       __a		)     ->		Union[str, Any]:







  """simple docstring"""





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





def      lowerCAmelCase_ (       __a	,    __a		)     ->		Dict:







  """simple docstring"""





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





def      lowerCAmelCase_ (       __a	,    __a	,    __a		)     ->		Optional[Any]:







  """simple docstring"""





  lowerCamelCase__:      Union[str, Any]			  =np.dot(__a	,    __a		)
  return np.sum(y * scores - np.log(1 + np.exp(__a		)		)		)





def      lowerCAmelCase_ (       __a	,    __a	,    __a	,    __a=70000		)     ->		List[str]:







  """simple docstring"""





  lowerCamelCase__:      Optional[Any]			  =np.zeros(x.shape[1]		)

  for iterations in range(__a		):
    lowerCamelCase__:      Tuple			  =np.dot(__a	,    __a		)
    lowerCamelCase__:      Union[str, Any]			  =sigmoid_function(__a		)
    lowerCamelCase__:      Union[str, Any]			  =np.dot(x.T	,    h - y		) / y.size
    lowerCamelCase__:      Optional[Any]			  =theta - alpha * gradient  # updating the weights
    lowerCamelCase__:      List[str]			  =np.dot(__a	,    __a		)
    lowerCamelCase__:      List[str]			  =sigmoid_function(__a		)
    lowerCamelCase__:      str			  =cost_function(__a	,    __a		)
    if iterations % 100 == 0:
      print(F"""loss: {j} \t"""		)  # printing the loss after every 100 iterations
  return theta


# In[68]:

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

     __A									=				0.1
     __A									=				logistic_reg(alpha, x, y, max_iterations=7_0000)
     print("theta: ", theta)  # printing the theta i.e our weights vector





     def      lowerCAmelCase_ (       __a		)     ->		Union[str, Any]:







       """simple docstring"""





       return sigmoid_function(
           np.dot(__a	,    __a		)		)  # 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))									=				(x[:, 0].min(), x[:, 0].max())
     ((__A)					,	(__A))									=				(x[:, 1].min(), x[:, 1].max())
     ((__A)					,	(__A))									=				np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
     __A									=				np.c_[xxa.ravel(), xxa.ravel()]
     __A									=				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 ...file_utils import _LazyModule, is_torch_available
from ...utils import OptionalDependencyNotAvailable


A_       : List[str]         =			{
    'configuration_gpt_neox_japanese': ['GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GPTNeoXJapaneseConfig'],
    'tokenization_gpt_neox_japanese': ['GPTNeoXJapaneseTokenizer'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_       : Optional[int]         =			[
	    'GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'GPTNeoXJapaneseForCausalLM',
	    'GPTNeoXJapaneseLayer',
	    'GPTNeoXJapaneseModel',
	    'GPTNeoXJapanesePreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_gpt_neox_japanese import GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoXJapaneseConfig
	from .tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_gpt_neox_japanese import (
		    GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
		    GPTNeoXJapaneseForCausalLM,
		    GPTNeoXJapaneseLayer,
		    GPTNeoXJapaneseModel,
		    GPTNeoXJapanesePreTrainedModel,
		)


else:
	import sys

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



