


import numpy as np
from matplotlib import pyplot as plt
from sklearn import datasets
def 				__lowerCamelCase						( UpperCAmelCase_						:		List[Any]						):




      """simple docstring"""





      return 1 / (1 + np.exp(-z						))
def 				__lowerCamelCase						( UpperCAmelCase_						:		Tuple ,  UpperCAmelCase_						:		Tuple						):




      """simple docstring"""





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




      """simple docstring"""





      a						:Dict 							=       np.dot(__snake_case ,  __snake_case						)
      return np.sum(y * scores - np.log(1 + np.exp(__snake_case						)						)						)
def 				__lowerCamelCase						( UpperCAmelCase_						:		Tuple ,  UpperCAmelCase_						:		Tuple ,  UpperCAmelCase_						:		Dict ,  UpperCAmelCase_						:		List[Any]=7_0000						):




      """simple docstring"""





      a						:Optional[int] 							=       np.zeros(x.shape[1]						)

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

     snake_case				:    Any       				=     0.1
     snake_case				:    Optional[Any]       				=     logistic_reg(alpha, x, y, max_iterations=7_00_00)
     print('''theta: ''', theta)  # printing the theta i.e our weights vector
     def 				__lowerCamelCase						( UpperCAmelCase_						:		str						):




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

     plt.legend()






     plt.show()







"""simple docstring"""





import datasets


_a														=		"""\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

_a														=		"""\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

_a														=		"""
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""



def       lowerCamelCase__		(			__snake_case,     __snake_case	)							->		str:


					"""simple docstring"""





					return (preds == labels).mean()






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,     _KWARGS_DESCRIPTION	)
class     _UpperCAmelCase(    datasets.Metric	):



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							return datasets.MetricInfo(
							    description=_DESCRIPTION				,		citation=_CITATION				,		inputs_description=_KWARGS_DESCRIPTION				,		features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''),
							            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''),
							        })				,		codebase_urls=[]				,		reference_urls=[]				,		format='''numpy'''				,		)




		def 						UpperCAmelCase							(					self				,		__a				,		__a)       ->       Dict:






							'''simple docstring'''
							return {"accuracy": simple_accuracy(__a				,		__a)}






