0
votes

I work on windows 7

this is my code

def Rup(x, y, w):
    odleglosc = np.dot(x,w)-y
    cost = np.sum(odleglosc**2) / (2*np.shape(x)[0])
    return odleglosc, cost

def REG(data_1, data_2, data_3, Tu, cou):

    i = 0
    while i < cou:
        dif, cost = Rup(data_1, data_2, data_3)
        grad = np.dot(data_1.transpose(), dif) / np.shape(data_1)[0]
        data_3 = data_3 - Tu * grad
        if i%200==0:
            print('Wyliczony error w ' + str(i) + " iteracji: ", cost)
        i+=1;
    return data_3

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.preprocessing import LabelEncoder

_DANE = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data';

iris = pd.read_csv(_DANE, names=['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'label'])
le = LabelEncoder()
iris['label'] = le.fit_transform(iris['label'])
X = np.array(iris.drop(['petal_width'], axis=1))
y = np.array(iris['petal_width'])
iris.head()

cros = 1/1000
coun= 10000
_, features = np.shape(X)
wagi = np.zeros(features)
wektor = REG(X, y, wagi, cros, coun)
print('--------------------------------------------------')
print(wektor)
print('--------------------------------------------------')
dif, cost = Rup(X, y, wektor)
print('Szukany Error', cost)

the error message looks as follows

Traceback (most recent call last):

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 1319, in do_open

h.request(req.get_method(), req.selector, req.data, headers,

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1230, in request

self._send_request(method, url, body, headers, encode_chunked)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1276, in _send_request

self.endheaders(body, encode_chunked=encode_chunked)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1225, in endheaders

self._send_output(message_body, encode_chunked=encode_chunked)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1004, in _send_output

self.send(msg)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 944, in send

self.connect()

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1399, in connect

self.sock = self._context.wrap_socket(self.sock,

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket

return self.sslsocket_class._create(

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create self.do_handshake()

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in do_handshake

self._sslobj.do_handshake()

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:/Users/lukasz/PycharmProjects/miw/test.py", line 26, in

iris = pd.read_csv(_DANE, names=['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'label'])

File "C:\Users\lukasz\PycharmProjects\miw\venv\lib\site-packages\pandas\io\parsers.py", line 685, in parser_f

return _read(filepath_or_buffer, kwds)

File "C:\Users\lukasz\PycharmProjects\miw\venv\lib\site-packages\pandas\io\parsers.py", line 439, in _read

fp_or_buf, _, compression, should_close = get_filepath_or_buffer(

File "C:\Users\lukasz\PycharmProjects\miw\venv\lib\site-packages\pandas\io\common.py", line 196, in get_filepath_or_buffer

req = urlopen(filepath_or_buffer)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 222, in urlopen

return opener.open(url, data, timeout)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 525, in open

response = self._open(req, data)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 542, in _open

result = self._call_chain(self.handle_open, protocol, protocol +

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 502, in _call_chain

result = func(*args)

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 1362, in https_open

return self.do_open(http.client.HTTPSConnection, req,

File "C:\Users\lukasz\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 1322, in do_open

raise URLError(err)

urllib.error.URLError:

Process finished with exit code 1

with the code should be all right because it works correctly on the pages of the online compiler

I don't know how to deal with this problem

please help me

1

1 Answers

1
votes

You can provide an SSL context and disable the verification.

import ssl
ssl._create_default_https_context = ssl._create_unverified_context