Today I wrote a python script to simply predict a number using regression. Whenever I try to run the script on my centOS or Ubunto server the script crashes after a few minutes.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from sklearn.linear_model import LinearRegression
import time
import numpy as np
from sklearn.svm import SVR
import pytz
from datetime import datetime
from sys import argv, exit
import os, psutil
################################################
if len(argv) != 5:
print (argv[0] + '<train count> <timeout(s)> <predict date(Y/M/D)> <predict clock(H:M:S)>')
exit(2)
X_predict = [(int(datetime.strptime(argv[3] + " " + argv[4], '%Y/%m/%d %H:%M:%S').timestamp()*(10000000)))]
################################################
X=[]
y=[]
#driver = webdriver.Chrome()
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://example.com/')
elem_xpath = '//div[contains(text(), "the number")]/following-sibling::div'
for i in range(1, int(argv[1])):
try:
elem = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, elem_xpath)))
print ("train => ", i)
X.append(int(time.time()*(10000000)))
y.append(int(elem.text.replace(',', '')))
time.sleep(int(argv[2]))
finally:
driver.quit
##############################################
X = np.array(X).reshape(-1, 1)
y = np.array(y).reshape(-1, 1)
X_predict = np.array(X_predict).reshape(-1, 1)
##############################################
svr_rbf = LinearRegression()
y_rbf = svr_rbf.fit(X,y).predict(X_predict)
##########################################
#print ('X:'.format(X))
#print ('y:'.format(y))
#print ('X_predict:{}'.format(X_predict))
##########################################
print ('y_rbf: {}'.format(int(y_rbf)))
print('memory usage: {} MB'.format(
int(psutil.Process(os.getpid()).memory_info().rss/1024/1024)
))
Here is the screenshot where you can see the error and informations:
Is there any solution for it?