


# 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   (							A__							)	-> List[Any]:




      '''simple docstring'''

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




def    a   (							A__      ,    A__							)	-> Any:




      '''simple docstring'''

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




def    a   (							A__      ,    A__      ,    A__							)	-> Tuple:




      '''simple docstring'''

      SCREAMING_SNAKE_CASE__       :  str						     =		np.dot(A__      ,    A__							)
      return np.sum(y * scores - np.log(1 + np.exp(A__							)							)							)




def    a   (							A__      ,    A__      ,    A__      ,    A__=7_0_0_0_0							)	-> Tuple:




      '''simple docstring'''

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

      for iterations in range(A__							):
            SCREAMING_SNAKE_CASE__       :  List[Any]						     =		np.dot(A__      ,    A__							)
            SCREAMING_SNAKE_CASE__       :  Dict						     =		sigmoid_function(A__							)
            SCREAMING_SNAKE_CASE__       :  int						     =		np.dot(x.T      ,    h - y							) / y.size
            SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		theta - alpha * gradient  # updating the weights
            SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		np.dot(A__      ,    A__							)
            SCREAMING_SNAKE_CASE__       :  int						     =		sigmoid_function(A__							)
            SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		cost_function(A__      ,    A__							)
            if iterations % 1_0_0 == 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_ :Dict  							=			iris.data[:, :2]
    a_ :int  							=			(iris.target != 0) * 1

    a_ :Dict  							=			0.1
    a_ :str  							=			logistic_reg(alpha, x, y, max_iterations=7_00_00)
    print('theta: ', theta)  # printing the theta i.e our weights vector




    def    a   (							A__							)	-> int:




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

    plt.legend()





    plt.show()













import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__							,   unittest.TestCase ):
 __SCREAMING_SNAKE_CASE							=      CTRLTokenizer
 __SCREAMING_SNAKE_CASE							=      False
 __SCREAMING_SNAKE_CASE							=      False



 def 							UpperCamelCase     (				self					):
        super().setUp()

        # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
        A__		   =		['''adapt''', '''re@@''', '''a@@''', '''apt''', '''c@@''', '''t''', '''<unk>''']
        A__		   =		dict(zip(__lowerCamelCase,range(len(__lowerCamelCase					)					)					)					)
        A__		   =		['''#version: 0.2''', '''a p''', '''ap t</w>''', '''r e''', '''a d''', '''ad apt</w>''', '''''']
        A__		   =		{'''unk_token''': '''<unk>'''}

        A__		   =		os.path.join(self.tmpdirname,VOCAB_FILES_NAMES['''vocab_file''']					)
        A__		   =		os.path.join(self.tmpdirname,VOCAB_FILES_NAMES['''merges_file''']					)
        with open(self.vocab_file,'''w''',encoding='''utf-8'''					) as fp:
               fp.write(json.dumps(__lowerCamelCase					) + '''\n'''					)
        with open(self.merges_file,'''w''',encoding='''utf-8'''					) as fp:
               fp.write('''\n'''.join(__lowerCamelCase					)					)



 def 							UpperCamelCase     (				self,**__lowerCamelCase					):
        kwargs.update(self.special_tokens_map					)
        return CTRLTokenizer.from_pretrained(self.tmpdirname,**__lowerCamelCase					)



 def 							UpperCamelCase     (				self,__lowerCamelCase					):
        A__		   =		'''adapt react readapt apt'''
        A__		   =		'''adapt react readapt apt'''
        return input_text, output_text




 def 							UpperCamelCase     (				self					):
        A__		   =		CTRLTokenizer(self.vocab_file,self.merges_file,**self.special_tokens_map					)
        A__		   =		'''adapt react readapt apt'''
        A__		   =		'''adapt re@@ a@@ c@@ t re@@ adapt apt'''.split()
        A__		   =		tokenizer.tokenize(__lowerCamelCase					)
        self.assertListEqual(__lowerCamelCase,__lowerCamelCase					)

        A__		   =		tokens + [tokenizer.unk_token]

        A__		   =		[0, 1, 2, 4, 5, 1, 0, 3, 6]
        self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowerCamelCase					),__lowerCamelCase					)





