'''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 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






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



def 							UpperCamelCase__			(			a__			,      a__      ):


						'''simple docstring'''






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



def 							UpperCamelCase__			(			a__			,      a__			,      a__      ):


						'''simple docstring'''






						_lowerCAmelCase										=np.dot(a__			,      a__      )
						return np.sum(y * scores - np.log(1 + np.exp(a__      )      )      )



def 							UpperCamelCase__			(			a__			,      a__			,      a__			,      a__=7_0_0_0_0      ):


						'''simple docstring'''






						_lowerCAmelCase										=np.zeros(x.shape[1]      )

						for iterations in range(a__      ):
												_lowerCAmelCase										=np.dot(a__			,      a__      )
												_lowerCAmelCase										=sigmoid_function(a__      )
												_lowerCAmelCase										=np.dot(x.T			,      h - y      ) / y.size
												_lowerCAmelCase										=theta - alpha * gradient  # updating the weights
												_lowerCAmelCase										=np.dot(a__			,      a__      )
												_lowerCAmelCase										=sigmoid_function(a__      )
												_lowerCAmelCase										=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__":
							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_0000)
							print('''theta: ''', theta)  # printing the theta i.e our weights vector



							def 							UpperCamelCase__			(			a__      ):


													'''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''')
							((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()






'''simple docstring'''

lowercase_     		= {
    '''A''': '''.-''', '''B''': '''-...''', '''C''': '''-.-.''', '''D''': '''-..''', '''E''': '''.''', '''F''': '''..-.''', '''G''': '''--.''',
    '''H''': '''....''', '''I''': '''..''', '''J''': '''.---''', '''K''': '''-.-''', '''L''': '''.-..''', '''M''': '''--''', '''N''': '''-.''',
    '''O''': '''---''', '''P''': '''.--.''', '''Q''': '''--.-''', '''R''': '''.-.''', '''S''': '''...''', '''T''': '''-''', '''U''': '''..-''',
    '''V''': '''...-''', '''W''': '''.--''', '''X''': '''-..-''', '''Y''': '''-.--''', '''Z''': '''--..''', '''1''': '''.----''',
    '''2''': '''..---''', '''3''': '''...--''', '''4''': '''....-''', '''5''': '''.....''', '''6''': '''-....''', '''7''': '''--...''',
    '''8''': '''---..''', '''9''': '''----.''', '''0''': '''-----''', '''&''': '''.-...''', '''@''': '''.--.-.''',
    ''':''': '''---...''', ''',''': '''--..--''', '''.''': '''.-.-.-''', '''\'''': '''.----.''', '''"''': '''.-..-.''',
    '''?''': '''..--..''', '''/''': '''-..-.''', '''=''': '''-...-''', '''+''': '''.-.-.''', '''-''': '''-....-''',
    '''(''': '''-.--.''', ''')''': '''-.--.-''', '''!''': '''-.-.--''', ''' ''': '''/'''
}  # Exclamation mark is not in ITU-R recommendation
# fmt: on
lowercase_     		= {value: key for key, value in MORSE_CODE_DICT.items()}



def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						return " ".join(MORSE_CODE_DICT[char] for char in message.upper()      )



def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						return "".join(REVERSE_DICT[char] for char in message.split()      )



def 							UpperCamelCase__			(			):


						'''simple docstring'''






						_lowerCAmelCase										='Morse code here!'
						print(a__      )
						_lowerCAmelCase										=encrypt(a__      )
						print(a__      )
						_lowerCAmelCase										=decrypt(a__      )
						print(a__      )


if __name__ == "__main__":
							main()





