SHARE
TWEET

Untitled

a guest Dec 14th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2. import datetime
  3.  
  4.  
  5. import lpputils  as lu
  6. import linear as li
  7. import numpy as np
  8. # import  holidays
  9.  
  10. def testna(departureDataUcna, arrivalDataUcna):
  11.     departureData = []
  12.  
  13.     with open("./train_pred/train_pred.csv", "r") as f:
  14.         reader = csv.reader(f, delimiter="\t")
  15.         next(reader)
  16.         for i in reader:
  17.  
  18.             departure = lu.parsedate(i[6])
  19.             voznik = float(i[1]) * 1000
  20.  
  21.             # znacilke
  22.             vikend = 1
  23.             praznik = 0
  24.  
  25.             # pon-pet
  26.             if departure.weekday() < 5:
  27.                 vikend = 1000000
  28.  
  29.             # nedelja ali praznik
  30.             if departure.weekday() == 6:
  31.                 praznik = 1000000
  32.  
  33.             # prazniki
  34.             if departure.month == 1 and (departure.day == 1 or departure.day == 2):
  35.                 praznik = 1000000
  36.             if departure.month == 2 and departure.day == 8:
  37.                 praznik = 1000000
  38.             if departure.month == 4 and (departure.day == 8 or departure.day == 9 or departure.day == 27):
  39.                 praznik = 1000000
  40.             if departure.month == 5 and (departure.day == 1 or departure.day == 2 or departure.day == 31):
  41.                 praznik = 1000000
  42.             if departure.month == 6 and departure.day == 25:
  43.                 praznik = 1000000
  44.             if departure.month == 8 and departure.day == 15:
  45.                 praznik = 1000000
  46.             if departure.month == 10 and departure.day == 31:
  47.                 praznik = 1000000
  48.             if departure.month == 11 and departure.day == 1:
  49.                 praznik = 1000000
  50.             if departure.month == 12 and (departure.day == 25 or departure.day == 26):
  51.                 praznik = 1000000
  52.  
  53.             gneca = 0
  54.  
  55.             if 17 >= departure.hour >= 7:
  56.                 gneca = departure.hour * 100000000000
  57.  
  58.             departureData.append([departure.timestamp(), gneca, vikend, praznik, voznik])
  59.  
  60.     xUcna = np.array(departureDataUcna)
  61.     y = np.array(arrivalDataUcna)
  62.     lr = li.LinearLearner(lambda_=1.)
  63.     linear = lr(xUcna, y)
  64.  
  65.     xTestna = np.array(departureData)
  66.  
  67.     f = open('izhod.txt', 'w')
  68.     napoved = []
  69.     for i,j in zip(xTestna,departureDataUcna):
  70.         i = datetime.datetime.fromtimestamp(linear(i))
  71.         napoved.append(float(str(linear(j) )))
  72.  
  73.         f.write(str(i) + "\n")
  74.  
  75.     print("MAE ", np.mean([abs(m- n) for m,n in zip(arrivalDataUcna, napoved)]))
  76.  
  77.  
  78.  
  79. if __name__ == "__main__":
  80.  
  81.     # departureData, arrivalData,gnecaData, vikendData, praznikData  = preberiUcnePodatke()
  82.  
  83.     departureData = []
  84.     arrivalData = []
  85.  
  86.     with open("./train_pred/train_pred.csv", "r") as f:
  87.         reader = csv.reader(f, delimiter="\t")
  88.  
  89.         next(reader)
  90.         for i in reader:
  91.  
  92.             departure = lu.parsedate(i[6])
  93.             arrival = lu.parsedate(i[8])
  94.             voznik = float(i[1]) * 1000
  95.  
  96.             vikend = 1
  97.             praznik = 0
  98.  
  99.             # si_holidays = holidays.SI()
  100.  
  101.             # pon-pet
  102.             if departure.weekday() < 5:
  103.                 vikend = 1000000
  104.  
  105.             # nedelja ali praznik
  106.             if departure.weekday() == 6:
  107.                 praznik = 1000000
  108.  
  109.             # prazniki
  110.             if departure.month == 1 and (departure.day == 1 or departure.day == 2):
  111.                 praznik = 1000000
  112.             if departure.month == 2 and departure.day == 8:
  113.                 praznik = 1000000
  114.             if departure.month == 4 and (departure.day == 8 or departure.day == 9 or departure.day == 27):
  115.                 praznik = 1000000
  116.             if departure.month == 5 and (departure.day == 1 or departure.day == 2 or departure.day == 31):
  117.                 praznik = 1000000
  118.             if departure.month == 6 and departure.day == 25:
  119.                 praznik = 1000000
  120.             if departure.month == 8 and departure.day == 15:
  121.                 praznik = 1000000
  122.             if departure.month == 10 and departure.day == 31:
  123.                 praznik = 1000000
  124.             if departure.month == 11 and departure.day == 1:
  125.                 praznik = 1000000
  126.             if departure.month == 12 and (departure.day == 25 or departure.day == 26):
  127.                 praznik = 1000000
  128.  
  129.             gneca = 0
  130.  
  131.             if 17 >= departure.hour >= 7:
  132.                 gneca = departure.hour * 100000000000
  133.  
  134.             departureData.append([departure.timestamp(), gneca, vikend, praznik, voznik])
  135.             arrivalData.append(lu.tsdiff(arrival, departure))
  136.             # arrivalData.append(arrival.timestamp())
  137.  
  138.     testna(departureData,arrivalData)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top