Predicting Stock Prices - Learn Python for Data Science #4

Siraj Raval · 841K views · 2016 · 7:39

Open on YouTube

Machine learning & deep learningPython, Ruby & scripting languagesData science & statisticstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the source of the SVR stock-prediction code they are adapting or debugging, usually when the model gives odd output or they don't understand part of the script.

Recommended by 0 people across 0 different months, 2017 to 2021.

What it is

A short Siraj Raval tutorial that builds an Apple stock price predictor in about 40 lines of Python. It uses scikit-learn's support vector regression (linear, polynomial and RBF kernels) and plots the results with matplotlib.

What people said

Cites dark.vador · 2017-01 · Stack Overflow · on “Support Vector Machine Python 3.5.2”

While searching some tutorial on SVM , I've found online - Support Vector Machine _ Illustration [this video] - the below code, which is however yielding a weird chart. After debugging the code, I wonder if the cause lies on the Date list, precisely: dates.append(int(row[0].split('-')[0])) which is static from my side (i.e 2016) or if there is something else, although I am not seeing anything abnormal within the code. EDIT This deduction is coming from the syntax: plt.scatter(dates, prices, color ='black', label ='Data'); plt.show() yielding the vertical line, factually, whereas dates.append(int(row[0].split('-')[0])) is supposed, as described in the link and also reflected into the code, to conv

Cites Ben Williams · 2019-03 · Stack Overflow · on “SVR predicts same value for all features”

I'm creating a basic application to predict the 'Closing' value of a stock for day n+1, given features of stock n using Python and Scikit-learn A sample row in my dataframe looks like this (2000 rows) Open Close High Low Volume 0 537.40 537.10 541.55 530.47 52877.98 Similar to this video [this video] , where he uses 'Dates' and 'Open Price'. In this example, Dates are the features and Open price is the target. Now in my example, I don't have a 'Dates' value in my dataset, but instead want to use Open, High, Low, Volume data as the features because I thought that would make it more accurate I was defining my features and targets as so features = df.loc[:,df.columns != 'Closing'] targets = df.loc[:

Cites TheGodParticle · 2021-08 · Stack Overflow · on “What is 'x' in def predict_prices(dates, prices, x)”

import csv import numpy as np from sklearn.svm import SVR import matplotlib.pyplot as plt dates = [] prices = [] def get_data(filename): with open(filename, 'r') as csvfile: csvFileReader = csv.reader(csvfile) next(csvFileReader) for row in csvFileReader: dates.append(int(row[0].split('/')[1])) flt_price = row[3].replace('$', '') prices.append(float(flt_price)) return def predict_prices(dates, prices, x): dates = np.reshape(dates, (len(dates), 1)) svr_lin = 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_lin.fit(dates, prices) svr_poly.fit(dates, prices) svr_rbf.fit(dates, prices) plt.scatter(dates,