


# 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 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__						):
 return 1 / (1 + np.exp(-z						))
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						):
 return (-y * np.log(SCREAMING_SNAKE_CASE__						) - (1 - y) * np.log(1 - h						)).mean()
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						):
 __lowerCamelCase		:							Any		 =						np.dot(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)
 return np.sum(y * scores - np.log(1 + np.exp(SCREAMING_SNAKE_CASE__						)						)						)
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__=70_000						):
 __lowerCamelCase		:							str		 =						np.zeros(x.shape[1]						)

 for iterations in range(SCREAMING_SNAKE_CASE__						):
  __lowerCamelCase		:							Optional[Any]		 =						np.dot(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)
  __lowerCamelCase		:							str		 =						sigmoid_function(SCREAMING_SNAKE_CASE__						)
  __lowerCamelCase		:							List[Any]		 =						np.dot(x.T      ,	h - y						) / y.size
  __lowerCamelCase		:							Tuple		 =						theta - alpha * gradient  # updating the weights
  __lowerCamelCase		:							Optional[int]		 =						np.dot(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)
  __lowerCamelCase		:							Union[str, Any]		 =						sigmoid_function(SCREAMING_SNAKE_CASE__						)
  __lowerCamelCase		:							List[Any]		 =						cost_function(SCREAMING_SNAKE_CASE__      ,	SCREAMING_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=7_0_0_0_0)
       print('theta: ', theta)  # printing the theta i.e our weights vector
       def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__						):
        return sigmoid_function(
            np.dot(SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						)						)  # predicting the value of probability from the logistic regression algorithm

       plt.figure(figsize=(1_0, 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_)   ,(lowercase_))	   =     (x[:, 0].min(), x[:, 0].max())
       ((lowercase_)   ,(lowercase_))	   =     (x[:, 1].min(), x[:, 1].max())
       ((lowercase_)   ,(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()





import warnings

from ...utils import logging
from .image_processing_chinese_clip import ChineseCLIPImageProcessor


lowercase_	   =     logging.get_logger(__name__)


class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      def __init__(    self:	List[str]						,				*a:	List[Any]						,				**a:	Optional[Any]    ):
       warnings.warn(
           'The class ChineseCLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
           ' Please use ChineseCLIPImageProcessor instead.'						,				a						,				)
       super().__init__(*a						,				**a    )

