#machine learning


Linear Regression with Multiple Variables


x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] z = [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] def SlopeD1(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 * y[i]) + yInt difference = (z[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def SlopeD2(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 * y[i]) + yInt difference = (z[i] - predicted) * y[i] total += difference returnValue = (-2/length) * total return returnValue def InterceptD(x, y, z, slope1, slope2, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope1 * x[i]) + (slope2 *y[1]) + yInt difference = (z[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m1 = 0 m2 = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): mm1 = SlopeD1(x, y, z, m1, m2 ,c) mm2 = SlopeD2(x, y, z, m1, m2 ,c) yint = InterceptD(x, y, z, m1, m2 ,c) m1 = m1 - (l * mm1) m2 = m2 - (l * mm2) c = c - (l * yint) #print(m1, m2, c) print ('(', end ='' ) print(m1, end=', ') print(m2, end=', ') print(c, end=')')

Linear Regression


x = [1, 5, 3, 4, 7, 9, 12, 13, 15, 16, 17, 4, 5, 2, 10, 23, 25] y = [5, 12, 23, 14, 17, 8, 20, 21, 25, 38, 42, 10, 13, 7, 23, 50, 55] def SlopeD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def InterceptD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): slope = SlopeD(x, y, m ,c) intercept = InterceptD(x, y, m ,c) m = m - (l * slope) c = c - (l * intercept) print (m, c)

Linear Regression

A linear regression program which shows the slope of the line and y-intercept

import numpy as np import matplotlib.pyplot as plt def estimate_coef(x, y): n = np.size(x) m_x, m_y = np.mean(x), np.mean(y) SS_xy = np.sum(y*x) - n*m_y*m_x SS_xx = np.sum(x*x) - n*m_x*m_x b_1 = SS_xy / SS_xx b_0 = m_y - b_1*m_x return(b_0, b_1) def plot_regression_line(x, y, b): plt.scatter(x, y, color = "m", marker = "o", s = 30) y_pred = b[0] + b[1]*x plt.plot(x, y_pred, color = "g") plt.xlabel('x') plt.ylabel('y') plt.show() def main(): x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12]) b = estimate_coef(x, y) print("Estimated coefficients:\nb_0 = {} \" \nb_1 = {}".format(b[0], b[1]")) plot_regression_line(x, y, b) if __name__ == "__main__": main()

Linear Regression

This is Linear Regression


x = [15, 9, 12, 1, 10, 11, 4, 16, 2, 30, 4, 15, 18, 12, 14] y = [13 ,19, 16, 15, 24, 7, 18, 23, 28, 2, 26, 12, 18, 24, 17] def DerivativeSlope(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def DerivativeIntercept(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): slope = DerivativeSlope(x, y, m ,c) intercept = DerivativeIntercept(x, y, m ,c) m = m - (l * slope) c = c - (l * intercept) print (m, c)

Hierarchical Clustering

This program is hierarchical clustering without sklearn.


import math def cluster(table, maximum, k): for i in range(k): max1 = 10000 a = table[i] for f in range(k): if i !=f: b = table[f] distance =0 for i in range(3): distance += math.sqrt((a[i][0]-b[i][0])**2 + (a[i][1]-b[i][1])**2 + (a[i][2]-b[i][2])**2) if distance<max1: max1 = distance hello = f if max1 < maximum: indeces = (i, hello) return (indeces) def avg(a, b, table): e = table[a] f = table[b] new = [] for i in range(3): g = e[i] h = f[i] new.append(((g[0]+h[0])/2, (g[1]+h[1])/2,(g[2]+h[2])/2)) return (new) def recursion(table, k): if k ==2: table = avg(0, 1, table) return (table) else: maximum = 10000000 a= cluster(table, maximum, k) index1= a[0] index2= a[1] #print (index1, index2) newCluster = avg(index1, index2, table) table[index1] = newCluster table.pop(index2) return recursion(table, k-1) table = [[(1, 5,7), (1, 6, 2), (5, 3, 1)], [(2, 3, 4), (1, 2, 7), (2, 1, -5)],[(-1, -1, -1), (0, 0, 0), (3, 3, 3)], [(2, 12, 3), (2, 4, 1), (2, 4, 5)]] a = recursion(table, 4) print (str(a[0]) + " and " + str(a[1]) + " and " + str(a[2]))

Finding closest data type using "n" number of nearest neighbors

Given a set of data (traindata) which assigns certain coordinates to a binary system of colors, this program uses this data to find the color of best fit for a coordinate (testdata) given by the user. Ultimately, any coordinate entered by the user should produce either "black" or "blue." Solved by appending the distances from each training coordinate to the testing coordinate to a list called "distances," and finding the minimum value of that list each time around. To avoid repetition in calculation of minimums, I replaced each value that had already been tested with float('inf').

import math traindata = [(1,1,"blue"), (2,2,"blue"), (3,3,"black"), (4,4,"blue"), (5,5,"black"), (4,3,"blue"), (4,10,"black"), (5,5,"black"), (6,2,"blue"), (1,7,"black"), (4,9,"blue"), (5,8,"blue")] testdata = [] testdatax = int(input("Enter the x coordinate of your testing data: ")) testdatay = int(input("Enter the y coordinate of your testing data: ")) n = int(input("Enter the number of nearest neighbors you wish to calculate: ")) testdata.append(testdatax) testdata.append(testdatay) distances = [] for x in traindata: a = x[0] b = x[1] distance = math.sqrt((abs(a - testdatax))^2 + (abs(b-testdatay))^2) distances.append(distance) mindistances = [] indices = [] while len(mindistances) < n: mindistance = min(distances) mindistances.append(mindistance) u = distances.index(mindistance) indices.append(u) distances[u] = float('inf') colors = [] for m in indices: value = traindata[m] color = value[2] colors.append(color) blues = [] blacks = [] for k in colors: if k == "blue": blues.append(k) elif k == "black": blacks.append(k) if len(blues)> len(blacks): print("Blue") elif len(blacks)> len(blues): print("Black")

K Means Clustering

import math import statistics import random centroids = [(random.randint(0, 12), random.randint(0, 12), random.randint(0, 12), "blue"), (random.randint(0, 12), random.randint(0, 12), random.randint(0, 12), "green"), (random.randint(0, 12), random.randint(0, 12), random.randint(0, 12), "red")] data = [(3,5 , 10), (4, 12, 1), (7, 8, 5), (2, 6, 11), (3, 1, 4), (4, 1, 7), (1, 2, 3), (5, 1, 3), (6, 2, 3)] length2 = len(data) NewData = [] def FindClosest(centroid, xvalue, yvalue, zvalue): base = 100000 length = len(centroid) for i in range(length): a = centroids[i] x = a[0] y = a[1] z = a[2] distance = math.sqrt(abs(xvalue - x)**2 + abs(yvalue-y)**2 + abs(zvalue-z)**2) if distance < base: base = distance place = i return (place) def ChooseColor(place, centroids): a = centroids[place] color = a[3] return (color) for i in range(length2): a = data[i] xvalue = a[0] yvalue = a[1] zvalue = a[2] NewData.append((xvalue, yvalue, zvalue, ChooseColor(FindClosest(centroids, xvalue, yvalue, zvalue), centroids))) for i in range(len(NewData)): a = NewData[i] print ("(" + str(a[0]) + ", " + str(a[1]) + ", " + str(a[2]) + ") , color = " + a[3])

The World of Stocks

In this project, we used data from the QUANDL API to get different calculations of stocks, such as volatility, average price, and correlation coefficient. It also allowed the user to input a stock and enter how many units and when they bought it. It then calculated the amount of money they earned with the stock. The most impressive part of this project was the implementation of machine learning to estimate the future price of an inputted stock based on previous years. We used the package, sklearn, to do the machine learning. This project was used at a hackathon.


import sys from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow from PyQt5.uic import loadUi from PyQt5 import QtWidgets import quandl import math import dash import dash_core_components as dcc import dash_html_components as html import threading import numpy as np import datetime from sklearn.linear_model import LinearRegression from sklearn import preprocessing, model_selection, svm from sklearn.svm import SVR class MainWindow(QMainWindow): #link the UI def __init__(self): super(MainWindow, self).__init__() loadUi('homepage.ui', self) quandl.ApiConfig.api_key = "Ui3JT8HDDV3vnADUsD2k" #call the fill combobox function x=self.fillCombobox() #call the function to take the text from the combobox self.pushButton_2.clicked.connect(self.averageStock) #call the function to graph a stock self.pushButton_2.clicked.connect(self.visual) self.pushButton_3.clicked.connect(self.visual) self.pushButton_4.clicked.connect(self.visual) self.pushButton_5.clicked.connect(self.visual) #call the function to calculate calculate correlation self.pushButton_5.clicked.connect(self.calcCoCo) #call the function to graph correlation data self.pushButton.clicked.connect(self.graph) self.pushButton_4.clicked.connect(self.visual2) self.pushButton_3.clicked.connect(self.graph2) self.pushButton_4.clicked.connect(self.graph3) #call the function to graph related data self.pushButton_5.clicked.connect(self.visual3) self.pushButton_7.clicked.connect(self.futureDate) self.pushButton_8.clicked.connect(self.futureStocks) self.pushButton_9.clicked.connect(self.volatility) #function for filling the comboboxes def fillCombobox(self): companies=['WIKI/AAPL', 'WIKI/GOOGL', 'WIKI/TSLA', 'WIKI/IBM', 'WIKI/WMT', 'WIKI/T', 'WIKI/AMZN', 'WIKI/INTC', 'WIKI/NKE', 'WIKI/EA'] #fill the stock comboboxes for company in companies: self.comboBox.addItem(company) self.comboBox_2.addItem(company) self.comboBox_3.addItem(company) self.comboBox_4.addItem(company) self.comboBox_22.addItem(company) self.comboBox_19.addItem(company) self.comboBox_24.addItem(company) #fill the year comboboxes for i in range(2007, 2019): self.comboBox_6.addItem(str(i)) self.comboBox_7.addItem(str(i)) self.comboBox_8.addItem(str(i)) self.comboBox_25.addItem(str(i)) self.comboBox_26.addItem(str(i)) self.comboBox_9.addItem(str(i)) self.comboBox_11.addItem(str(i)) self.comboBox_12.addItem(str(i)) self.comboBox_18.addItem(str(i)) self.comboBox_14.addItem(str(i)) for i in range(2019, 2030): self.comboBox_23.addItem(str(i)) for i in range(13): if i < 10: self.comboBox_21.addItem("0" + str(i)) self.comboBox_17.addItem("0" + str(i)) else: self.comboBox_21.addItem(str(i)) self.comboBox_17.addItem(str(i)) for i in range(32): if i < 10: self.comboBox_15.addItem("0" + str(i)) self.comboBox_20.addItem("0" + str(i)) else: self.comboBox_15.addItem(str(i)) self.comboBox_20.addItem(str(i)) for i in range(10000, 100000, 10000): self.comboBox_16.addItem(str(i)) #function for taking the text from the comboboxes def averageStock(self): company=self.comboBox.currentText() year_start=int(self.comboBox_8.currentText()) year_end=int(self.comboBox_9.currentText()) listC = [] totalC = 0 for i in range(year_start, year_end+1): df = quandl.get(company, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() listC.append(y) totalC += y avgC = totalC / len(listC) self.textEdit_27.setText(str(avgC)) #functions to graph a stock def visual(self): threading.Thread(target=self.graph, daemon=True).start() def graph(self): #make the list for the y values company=self.comboBox_4.currentText() year_start=int(self.comboBox_7.currentText()) year_end=int(self.comboBox_6.currentText()) listC = [] totalC = 0 for i in range(year_start, year_end+1): print(i) df = quandl.get(company, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() listC.append(y) #make the list for the x values years=[] for i in range(year_start, year_end+1): years.append(i) #make the graph app = dash.Dash() app.layout = html.Div(children=[ html.H1(children=str(company)+' Graph'), html.Div(children='Graph of '+str(company)+' In The Years '+str(year_start)+' through '+str(year_end) ), dcc.Graph( id='ui-graphicvisualization', figure={ 'data': [ {'x': years, 'y': listC, 'type': 'line', 'name': company}, ], 'layout': { 'title': str(company) } } ) ]) app.run_server(port=1111) #function to calculate correlation def futureDate(self): sday = self.comboBox_15.currentText() smonth = self.comboBox_21.currentText() syear = self.comboBox_18.currentText() eday = self.comboBox_20.currentText() emonth = self.comboBox_17.currentText() eyear = self.comboBox_14.currentText() valueInvested = self.comboBox_16.currentText() inputStock = self.comboBox_22.currentText() startDay = quandl.get(str(inputStock), start_date = str(syear) + "-" + str(smonth) + "-" + str(sday) , end_date = str(syear) + "-" + str(smonth) + "-" + str(sday)) endDay = quandl.get(str(inputStock), start_date = str(eyear) + "-" + str(emonth) + "-" + str(eday) , end_date = str(eyear) + "-" + str(emonth) + "-" + str(eday)) x = startDay["High"].mean() y = endDay["High"].mean() percentChange = (y-x)/x finalAmt = int(valueInvested) * (1 + percentChange) self.textEdit_28.setText(str(finalAmt)) def futureStocks(self): company=self.comboBox_19.currentText() years=[] prices=[] for i in range(2007,2019): #make a list of years from 2007 to 2018 years.append(i) #make a list of averages for each year df=quandl.get(company, start_date=str(i)+"-01-01", end_date=str(i)+"-01-10") y=df["High"].mean() prices.append(y) print (prices) #create variable for third parameter of predict_stock_prices function futureYear=int(self.comboBox_23.currentText()) x=(futureYear-2018)*365 print (x) def predict_stock_prices(years, prices, x): years = np.reshape(years, (len(years),1 )) prices = np.reshape(prices, (len(prices),1)) svr_rbf = SVR(kernel = 'rbf', C=1e3, gamma=0.1) svr_rbf.fit(years, prices) return svr_rbf.predict(x)[0] predicted_prices = predict_stock_prices(years, prices, [[x]]) self.textEdit_32.setText(str(predicted_prices)) def volatility(self): inputStock = self.comboBox_24.currentText() year_start=int(self.comboBox_25.currentText()) year_end=int(self.comboBox_26.currentText()) listC = [] totalC = 0 num = 0 for i in range(year_start, year_end+1): df = quandl.get(inputStock, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() listC.append(y) totalC += y num += 1 avgC = totalC / len(listC) diffs= [] for i in listC: poop = (avgC - i) ** 2 diffs.append(poop) hello = 0 for i in diffs: hello += int(i) volatility = float((hello / len(listC))** 0.5) self.textEdit_35.setText(str(volatility)) def calcCoCo(self): inputCompany=self.comboBox_2.currentText() company=self.comboBox_3.currentText() year_start=int(self.comboBox_11.currentText()) year_end=int(self.comboBox_12.currentText()) listInput = [] totalInput = 0 listComp = [] totalComp = 0 for i in range(year_start, year_end+1): df = quandl.get(str(inputCompany), start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") df2 = quandl.get(str(company), start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() x= df2["High"].mean() listInput.append(y) totalInput += y listComp.append(x) totalComp += x avgInput = totalInput / len(listInput) avgComp = totalComp / len(listComp) listCompSquared = [] listInputSquared = [] mult = [] #to find the standard devations, u nee to find bot lists squared for i in listInput: listInputSquared.append(i**2) for i in listComp: listCompSquared.append(i**2) #to print out the multiplication of both the values in both lists, set a varaibe for both equal to the i'th number in each list. When i is 2 in the for loop, the variable will be list[i] for i in range(0, len(listInput)): itemInput = listInput[i] itemComp = listComp[i] mult.append(itemComp * itemInput) #find the average of he squared list sumPowInput = sum(listInputSquared) avgSquareInput = sumPowInput / len(listInputSquared) sumPowComp = sum(listCompSquared) avgSquareComp = sumPowComp / len(listCompSquared) sumMult = sum(mult) avgMult = sum(mult)/len(mult) varInput = avgSquareInput - (avgInput **2 ) varComp = avgSquareComp - (avgComp **2 ) coVar = (avgMult) - (avgInput * avgComp) CoCo = coVar / (math.sqrt(varInput * varComp)) self.textEdit_26.setText(str(CoCo)) #functions for graphing correlation between two stocks def visual2(self): threading.Thread(target=self.graph2, daemon=True).start() def graph2(self): inputCompany=self.comboBox_2.currentText() company=self.comboBox_3.currentText() year_start=int(self.comboBox_11.currentText()) year_end=int(self.comboBox_12.currentText()) listInput = [] totalInput = 0 listComp = [] totalComp = 0 for i in range(year_start, year_end+1): df = quandl.get(inputCompany, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") df2 = quandl.get(company, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() x= df2["High"].mean() listInput.append(y) totalInput += y listComp.append(x) totalComp += x avgInput = totalInput / len(listInput) avgComp = totalComp / len(listComp) listCompSquared = [] listInputSquared = [] mult = [] #to find the standard devations, u nee to find bot lists squared for i in listInput: listInputSquared.append(i**2) for i in listComp: listCompSquared.append(i**2) #to print out the multiplication of both the values in both lists, set a varaibe for both equal to the i'th number in each list. When i is 2 in the for loop, the variable will be list[i] for i in range(0, len(listInput)): itemInput = listInput[i] itemComp = listComp[i] mult.append(itemComp * itemInput) #find the average of he squared list sumPowInput = sum(listInputSquared) avgSquareInput = sumPowInput / len(listInputSquared) sumPowComp = sum(listCompSquared) avgSquareComp = sumPowComp / len(listCompSquared) sumMult = sum(mult) avgMult = sum(mult)/len(mult) varInput = avgSquareInput - (avgInput **2 ) varComp = avgSquareComp - (avgComp **2 ) coVar = (avgMult) - (avgInput * avgComp) CoCo = coVar / (math.sqrt(varInput * varComp)) #make the x list consisting of the years years=[] for i in range(year_start, year_end+1): years.append(i) app = dash.Dash() app.layout = html.Div(children=[ html.H1(children='Correlation Coefficients'), html.Div(children=''' Graphs each company with eachother '''), dcc.Graph( id='example-graph-5', figure={ 'data': [ {'x': years, 'y': listInput, 'type': 'line', 'name': inputCompany}, {'x': years, 'y': listComp, 'type': 'line', 'name': company}, ], 'layout': { 'title': 'Correlation= '+str(CoCo) } } ), ]) app.run_server(port=2222) #functions for graphing correlation between first stock and list of other stocks def visual3(self): threading.Thread(target=self.graph3, daemon=True).start() def graph3(self): inputCompany=self.comboBox_4.currentText() year_start=int(self.comboBox_7.currentText()) year_end=int(self.comboBox_6.currentText()) #list of companies to loop through companies=['WIKI/AAPL', 'WIKI/GOOGL', 'WIKI/TSLA', 'WIKI/IBM', 'WIKI/WMT', 'WIKI/T', 'WIKI/AMZN', 'WIKI/INTC', 'WIKI/NKE', 'WIKI/EA'] #dictionary with each company and its correlation coefficient stockList=[] absstock=[] absstockDiction={} randstockDiction={} stockList=[] absstock=[] absstockDiction={} randstockDiction={} avgValuesDiction={} #calculate correlation for each company and append the values to a dictionary for company in companies: listInput = [] totalInput = 0 listComp = [] totalComp = 0 for i in range(year_start, year_end+1): df = quandl.get(inputCompany, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") df2 = quandl.get(company, start_date = str(i)+"-01-01", end_date = str(i)+"-12-31") y = df["High"].mean() x= df2["High"].mean() listInput.append(y) totalInput += y listComp.append(x) totalComp += x avgInput = totalInput / len(listInput) avgComp = totalComp / len(listComp) listCompSquared = [] listInputSquared = [] mult = [] for i in listInput: listInputSquared.append(i**2) for i in listComp: listCompSquared.append(i**2) for i in range(0, len(listInput)): itemInput = listInput[i] itemComp = listComp[i] mult.append(itemComp * itemInput) sumPowInput = sum(listInputSquared) avgSquareInput = sumPowInput / len(listInputSquared) sumPowComp = sum(listCompSquared) avgSquareComp = sumPowComp / len(listCompSquared) sumMult = sum(mult) avgMult = sum(mult)/len(mult) varInput = avgSquareInput - (avgInput **2 ) varComp = avgSquareComp - (avgComp **2 ) coVar = (avgMult) - (avgInput * avgComp) CoCo = coVar / (math.sqrt(varInput * varComp)) #append values to dictionaries/lists randstockDiction[company]=CoCo absstockDiction[abs(CoCo)]=company absstock.append(abs(CoCo)) avgValuesDiction[inputCompany]=listInput avgValuesDiction[company]=listComp #make final sorted dictionary absstock=sorted(absstock) i=9 while i>=0: comp=absstockDiction[absstock[i]] stockList.append([comp,randstockDiction[comp]]) i=i-1 #graph the related data years=[] for i in range(year_start, year_end+1): years.append(i) app = dash.Dash() app.layout = html.Div(children=[ html.H1(children='Correlation Coefficients: Related Data'), html.Div(children=''' Graphs each company with eachother and finds the correlation coefficient. '''), dcc.Graph( id='example-graph-6', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[0][0]], 'type': 'line', 'name': stockList[0][0]}, ], 'layout': { 'title': str(stockList[0][0]) } } ), dcc.Graph( id='example-graph-7', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[1][0]], 'type': 'line', 'name': stockList[1][0]}, ], 'layout': { 'title': str(stockList[1][0]) } } ), dcc.Graph( id='example-graph-8', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[2][0]], 'type': 'line', 'name': stockList[2][0]}, ], 'layout': { 'title': str(stockList[2][0]) } } ), dcc.Graph( id='example-graph-9', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[3][0]], 'type': 'line', 'name': stockList[3][0]}, ], 'layout': { 'title': str(stockList[3][0]) } } ), dcc.Graph( id='example-graph-10', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[4][0]], 'type': 'line', 'name': stockList[4][0]}, ], 'layout': { 'title': str(stockList[4][0]) } } ), dcc.Graph( id='example-graph-11', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[5][0]], 'type': 'line', 'name': stockList[5][0]}, ], 'layout': { 'title': str(stockList[5][0]) } } ), dcc.Graph( id='example-graph-12', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[6][0]], 'type': 'line', 'name': stockList[6][0]}, ], 'layout': { 'title': str(stockList[6][0]) } } ), dcc.Graph( id='example-graph-13', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[7][0]], 'type': 'line', 'name': stockList[7][0]}, ], 'layout': { 'title': str(stockList[7][0]) } } ), dcc.Graph( id='example-graph-14', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[8][0]], 'type': 'line', 'name': stockList[8][0]}, ], 'layout': { 'title': str(stockList[8][0]) } } ), dcc.Graph( id='example-graph-15', figure={ 'data': [ {'x': years, 'y': avgValuesDiction[inputCompany], 'type': 'line', 'name': inputCompany}, {'x': years, 'y': avgValuesDiction[stockList[9][0]], 'type': 'line', 'name': stockList[9][0]}, ], 'layout': { 'title': str(stockList[9][0]) } } ) ]) app.run_server(port=3333) app = QApplication(sys.argv) widget = MainWindow() widget.show() sys.exit(app.exec_())
1