<jupyter_start><jupyter_text>DegreeData :<jupyter_code>data = pd.read_csv('full_external_temperatures.csv',header=0, parse_dates=[0], index_col=0, squeeze=True)
x = []
temp_x = []
temp_x.extend(data['dateTime'])
for i in range(2000):
    x.append(temp_x[i])
    
x_data = []
for i in range(200):
    x_data.append(i)
y = []
temp_y = []
temp_y.extend(data['data'])
for i in range(200):
    y.append(temp_y[i])
test_y = []
temp_y = []
temp_y.extend(data['data'])
for i in range(2003):
    test_y.append(temp_y[i])
train = pd.DataFrame({'time':x_data,'value':y})
# Автокорегресія :
def auto_reg(a,b,p=1):
    w0,w1 = minMNK(a,b)
    function = w0
    #print(w0)
    result_array = []
    for i in range(p):
        len_arr = len(a) - i -1
        
        w0,w1 = minMNK(a[0:len_arr],b[0:len_arr])
        #print('liner - ',res_liner_regr, 'b - ',b[len_arr])
        function += b[len_arr] * w1
        
        result_array.append(function)
    return function
auto_reg(x_data,y,p=5)
# Скільзьке середнє :
def SMA(b,p=3):
    SMA_res = []
    sum_b = 0
    num = 0
    for i in range(len(b) - p):
        for j in range(p):
            sum_b += b[i+j]
        SMA_res.append(sum_b / p)
        sum_b = 0
    return SMA_res
def MA_foresee(b,p):
    SMA_res = 0

    for i in range(p):
        sum_b = len(b) - i -1
        SMA_res += b[sum_b]
        SMA_res /= p
    return SMA_res
def MAGrath(b,p=3):
    SMA_res = []
    sum_b = 0
    num = 0
    for i in range(len(b) - p):
        for j in range(p):
            sum_b += b[i+j]
        SMA_res.append(sum_b / p)
        sum_b = 0
    return SMA_res

MA_foresee(y,2)
MA_arr = [0,0,0]
temp_arr = SMA(y)
for i in range(len(temp_arr)):
    MA_arr.append(temp_arr[i])
plt.plot(x_data,MA_arr,'r')
plt.plot(x_data, y,'g')
plt.axis([0, 50, 0, 50])
plt.show()
test_y = []
temp_y = []
temp_y.extend(data['data'])
for i in range(2003):
    test_y.append(temp_y[i])
print(test_y[201])
def ARIMA(x,y,my_x,p,q,d):
    new_y = [0]
    new_y1 = []
    
    MA_plust_ar = 0
    
    if d == 0:
        MA_res = MA_foresee(y,q)
        AR_res = auto_reg(x_data,y,p=p)
        print("result MA = ", type(MA_res))
        print("result AR = ", type(AR_res))
        MA_plust_ar = MA_res + AR_res
        
        arr_MA = [0,0,0]
        temp_MA = MAGrath(y)
        for i in range(len(temp_MA)):
            tr = temp_MA[i]
            arr_MA.append(tr)
        plt.plot(x_data,arr_MA,'r')
        plt.plot(x_data,y,'b')
        plt.axis([-10, 210, -10, 20])
        plt.show()
    elif d == 1:
        for i in range(len(y)):
            num = y[i] - y[i-1]
            new_y.append(int(num))
            num = 0
        MA_res = MA_foresee(new_y,q)
        AR_res = auto_reg(x_data,new_y,p=p)
        print("result MA = ", MA_res)
        print("result AR = ", AR_res)
        MA_plust_ar = MA_res + AR_res
      
    elif d == 2:
        for i in range(len(y)):
            num = y[i] - y[i-1]
            new_y.append(int(num))
            num = 0
        for i in range(len(new_y)):
            num = new_y[i] - new_y[i-1]
            new_y1.append(num)
            num = 0
        arr_MA = SMA(new_y1,p)
        res_MA = 0
        for i in range(len(arr_MA)):
            res_MA += arrMA[i]
        arr_AR = auto_reg()
        
    return "predict " + str(MA_plust_ar)
        
print(ARIMA(x_data,y,my_x=1,p=1,q=7,d=0))
print("True value",test_y[201])
print(ARIMA(x_data,y,my_x=201,p=2,q=6,d=0))
def ARIMA_with_Prediction(step, x,y,p,q,d):
  new_y = [0]
  new_y1 = []
  
  resut_arr = []
  MA_plust_ar = 0
  
  if d == 0:
    new_x = []
    new_y = []
    new_x = x
    new_y = y
    my_x_x = 199
    for i in range(step):
      MA_res = MA_foresee(new_y,q)
      AR_res = auto_reg(new_x,new_y,p=p)
      MA_plust_ar = MA_res + AR_res
      resut_arr.append(MA_plust_ar)
      new_y.append(MA_plust_ar)
      my_x_x +=1
      new_x.append(my_x_x)

  return resut_arr
print("Predicted = ",ARIMA_with_Prediction(3,x_data,y,p=1,q=7,d=0))
print("True value = ", test_y[201],",   ",test_y[202],",   ",test_y[203])

from pyramid.arima import auto_arima
model = auto_arima(y, trace=True, error_action='ignore', suppress_warnings=True)
model.fit(y)
forecast = model.predict(3)
print("AutoArima : ",forecast)
print("Predicted = ",ARIMA_with_Prediction(3,x_data,y,p=1,q=7,d=0))
print("True value = ", test_y[201],",   ",test_y[202],",   ",test_y[203])<jupyter_output>AutoArima :  [10.27357231 10.27332909 10.27322035]
Predicted =  [10.39171210757265, 10.392524629546758, 10.381670780971682]
True value =  10.29 ,    10.13 ,    10.11
{'fraction_non_alphanumeric': 0.1607103705327779, 'fraction_numerical': 0.04889278666959, 'mean_word_length': 2.4692015209125477, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '395407', 'license': 'MIT', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2009, 'n_words': 350, 'path': 'FES-31/Ostap/ArimaPredict.ipynb', 'repo_name': 'artiiblack/rcs-research', 'size': '4561'}