

'''simple docstring'''






from __future__ import annotations

lowerCAmelCase__   		=      '''Muhammad Umer Farooq'''
lowerCAmelCase__   		=      '''MIT'''
lowerCAmelCase__   		=      '''1.0.0'''
lowerCAmelCase__   		=      '''Muhammad Umer Farooq'''
lowerCAmelCase__   		=      '''contact@muhammadumerfarooq.me'''
lowerCAmelCase__   		=      '''Alpha'''

import re
from html.parser import HTMLParser
from urllib import parse

import requests






class      lowercase_      (lowerCamelCase__ ):




  """simple docstring"""




  def __init__( self  :	Union[str, Any]   ,lowercase__  :	str     ):
   super().__init__()
   __lowercase				    =					[]
   __lowercase				    =					domain






  def    SCREAMING_SNAKE_CASE ( self  :	Union[str, Any]   ,lowercase__  :	str   ,lowercase__  :	list[tuple[str, str | None]]     ):
   # Only parse the 'anchor' tag.
   if tag == "a":
    # Check the list of defined attributes.
    for name, value in attrs:
     # If href is defined, and not empty nor # print it.
     if name == "href" and value != "#" and value != "":
      # If not already in urls.
      if value not in self.urls:
       __lowercase				    =					parse.urljoin(self.domain   ,lowercase__     )
       self.urls.append(lowercase__     )


def 						_A	(       A__ ):






 """simple docstring"""



 return ".".join(get_sub_domain_name(A__ ).split('''.''' )[-2:] )


def 						_A	(       A__ ):






 """simple docstring"""



 return parse.urlparse(A__ ).netloc


def 						_A	(       A__ = "https://github.com" ):






 """simple docstring"""



 __lowercase				    =					get_domain_name(A__ )

 # Initialize the parser
 __lowercase				    =					Parser(A__ )

 try:
  # Open URL
  __lowercase				    =					requests.get(A__ )

  # pass the raw HTML to the parser to get links
  parser.feed(r.text )

  # Get links and loop through
  __lowercase				    =					set()
  for link in parser.urls:
   # open URL.
   # read = requests.get(link)
   try:
    __lowercase				    =					requests.get(A__ )
    # Get the valid email.
    __lowercase				    =					re.findall('''[a-zA-Z0-9]+@''' + domain	,							read.text )
    # If not in list then append it.
    for email in emails:
     valid_emails.add(A__ )
   except ValueError:
    pass
 except ValueError:
  raise SystemExit(1 )

 # Finally return a sorted list of email addresses with no duplicates.
 return sorted(A__ )


if __name__ == "__main__":
 lowerCAmelCase__   		=      emails_from_url('''https://github.com''')
 print(f'{len(emails)} emails found:')
 print('''\n'''.join(sorted(emails)))





"""simple docstring"""






# 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__		)					->  str:
			return 1 / (1 + np.exp(-z		))





def 				A_       ( snake_case__       ,					snake_case__		)					->  str:
			return (-y * np.log(snake_case__		) - (1 - y) * np.log(1 - h		)).mean()





def 				A_       ( snake_case__       ,					snake_case__       ,					snake_case__		)					->  Union[str, Any]:
			_UpperCamelCase					:Tuple					     =	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__=7_00_00		)					->  Optional[int]:
			_UpperCamelCase					:Union[str, Any]					     =	np.zeros(x.shape[1]		)

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


# In[68]:

if __name__ == "__main__":
					UpperCamelCase__				:Union[str, Any]			   =	datasets.load_iris()
					UpperCamelCase__				:Dict			   =	iris.data[:, :2]
					UpperCamelCase__				:Any			   =	(iris.target != 0) * 1

					UpperCamelCase__				:Tuple			   =	0.1
					UpperCamelCase__				:List[str]			   =	logistic_reg(alpha, x, y, max_iterations=70_000)
					print("""theta: """, theta)  # printing the theta i.e our weights vector





					def 				A_       ( snake_case__		)					->  Optional[Any]:
								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""")
					((UpperCamelCase__)   ,			(UpperCamelCase__))				:Union[str, Any]			   =	(x[:, 0].min(), x[:, 0].max())
					((UpperCamelCase__)   ,			(UpperCamelCase__))				:Tuple			   =	(x[:, 1].min(), x[:, 1].max())
					((UpperCamelCase__)   ,			(UpperCamelCase__))				:Tuple			   =	np.meshgrid(np.linspace(xa_min, xa_max), np.linspace(xa_min, xa_max))
					UpperCamelCase__				:List[Any]			   =	np.c_[xxa.ravel(), xxa.ravel()]
					UpperCamelCase__				:List[Any]			   =	predict_prob(grid).reshape(xxa.shape)
					plt.contour(xxa, xxa, probs, [0.5], linewidths=1, colors="""black""")

					plt.legend()




					plt.show()

