A moment ago I started watching videos to use in a "practical" way Python in everyday life and I have a problem. My intention is to make a program in which I "predict" the curve in the bag that I could catch. Well my problem is that when I use the MultiProcessing (I do not know if it works the way I think), each kernel executes the program and runs it individually, and what I'm looking for is that they work all in one. My code is as follows:
import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
from multiprocessing import Process
import os
date = []
prices = []
processes = []
def get_data(file):
with open(file, "r") as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
date.append(int(row[0].split("-")[0]))
prices.append(float(row[1]))
return
def prediction(dates, prices, x):
dates = np.reshape(dates,(len(dates), 1))
svr_len = SVR(kernel="linear", C=1e3)
svr_poly = SVR(kernel="poly",C=1e3, degree = 2)
svr_rbf = SVR(kernel="rbf", C=1e3, gamma=0.1)
svr_len.fit(dates, prices)
svr_poly.fit(dates, prices)
svr_rbf.fit(dates, prices)
plt.scatter(dates, prices, color="black", label="Data")
plt.plot(dates, svr_rbf.predict(dates), color="red", label="RBF Model")
plt.plot(dates, svr_len.predict(dates), color="blue", label="Len Model")
plt.plot(dates, svr_poly.predict(dates), color="green", label="Poly Model")
plt.xlabel("Fecha")
plt.ylabel("Precio")
plt.title("Soporte para Vectro deR Regresión")
plt.legend()
plt.show()
return svr_poly.predict(x)[0], svr_rbf.predict(x)[0], svr_len.predict(x)[0]
get_data("IBEX.csv")
for n in range(os.cpu_count()):
processes.append(Process(target=prediction, args=(date, prices, 20))
for i in processes:
n.start()
for i in processes:
n.join()
I have also read the docs of MultiProcessing, but I do not understand very well what you put on the page, if someone will help me find the solution to the problem I would be grateful. Thanks in advance