Predicting Stock Prices – Learn Python for Data Science #4

Only a few days left to sign up for my new course! Learn more and sign-up here https://www.theschool.ai/courses/decentralized-applications
In this video, we build an Apple Stock Prediction script in 40 lines of Python using the scikit-learn library and plot the graph using the matplotlib library.

The challenge for this video is here:

Victor’s winning recommender code:

Kevin’s runner-up code:

I created a Slack channel for us, sign up here:

Stock prediction with Tensorflow:
Stock Market Prediction Using Multi-Layer Perceptrons With TensorFlow

Another great stock prediction tutorial:

This guy made 500K doing ML stuff with stocks:

Please share this video, like, comment and subscribe! That’s what keeps me going.

and please support me on Patreon!:

Check out this youtube channel for some more cool Python tutorials:

Follow me:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/

41 thoughts on “Predicting Stock Prices – Learn Python for Data Science #4”

  • The Ponzi Factor March 9, 2018 at 3:20 pm


    Good job explaining the data analysis.
    However, your assumption about how stocks work is completely wrong. Take the following into consideration to improve your model.

    Profits from stocks do not come from the profits of the company. They come from other investors who are buying and selling stocks. If you buy a stock for $10 and sell it at $11, that $11 come from another investor, not the company. The stock market is not romantic or mysterious, it is a disturbing system that just shuffles money between investors. (see the trailer below).

    The Ponzi Factor: Trailer

    The idea that company's share profits is a complete MYTH. Finance people advocate it because they sell stocks. They will argue "But companies can pay dividends, and they can buy back their own stocks…" Yes, hypothetically speaking that can happen, and hypothetically speaking, I can win the lottery too, but that does not happen in practices.
    In practice, companies (like Google) NEVER pay dividends or buy back their own stocks, and the only way for investors to make money is by selling stocks to other investors who also want to make money…which by definition, is also how a Ponzi scheme works!

    (Note: the value of a stock is a cerebral idea, not real money. This means the growth in stock value is meaningless if investors want money. The reality is, the stock market has grown to over $31 trillion, which means investors think they are entitled to $31 trillion, but there is only $3.8 trillion in the entire US economy!)

    QUESTION: What kind of scenarios/evidence can we expect to see if a stock is fundamentally disconnected from the company?

    1) Investors making money while the underlying company losses billions.
    2) Investors making nothing while the underlying company profits billions.

    EVIDENCE (from the book The Ponzi Factor):
    Tesla scenario: 2010–2017, the stock went from $20 to $380 while TESLA company lost $4.3 billion.
    Google scenario: 2007–2011, the stock stayed flat while the Google made over $28 billion.

    If you want to know more, check out my other videos.
    Debunk the myths. Share the truth.

  • Void Beats March 9, 2018 at 3:20 pm

    for some reason,similar code does not work for me (it shows an error).
    I didnt get the values from the web. I just entered my values in the lists. Does anyone know whats the problem?


  • VINAYAK RASTOGI March 9, 2018 at 3:20 pm


  • Diego Stefanon March 9, 2018 at 3:20 pm

    CNTK… why u do not speak about it ? Too much powerful? ))

  • tear728 March 9, 2018 at 3:20 pm

    This doesn't really "predict" it thought. All it does is fit a polynomial to the data that was in the past. No insight about what's going to happen in the future.

  • Frank Conte March 9, 2018 at 3:20 pm

    Nice video and I don't mind the pace. However, one of the modules is wrong.
    import matplotlib as plt
    doesn't work. After googling I found that
    import matplotlib.pyplot as plt
    provides results. Moreover my chart is nothing like the one in the video. The scatter is essentially one line. In addition, the results from the three models appear to be the same (i.e. in my last 30 days of AAPL stock that I used, I get
    166.86999499999999 for all three models.
    What gives?

  • Thomas Coe March 9, 2018 at 3:20 pm

    Hey Siraj! Sorry if this is a stupid question but how did you get the sklearn package to install with Sublime Text's python environment?

  • d parrott March 9, 2018 at 3:20 pm

    I am self-learning Python 3. My question is to import csv, numpy as np? , how sklearn.svm import SVR, import Matplotlib.pyplot as plt? Could someone help me how to install on windows these programs and do i import them before i start to code?

  • Bilal S. Meer March 9, 2018 at 3:20 pm

    I like the energy, need more help thou? Can you help me with a project?

  • Gourav Bais March 9, 2018 at 3:20 pm

    svr_lin = SVR(kernal = "Linear ", C = 1e3)
    Type error : 'module' object is not callable
    Anyone can help to resolve this error 😅

  • Explorer March 9, 2018 at 3:20 pm

    i didn't like this guy. but now i do nabour. why i am calling you out nabour. just check me out.

  • Brown Guy March 9, 2018 at 3:20 pm

    what is the last thing a human sees before dying 1:13

  • Даниил Устименко March 9, 2018 at 3:20 pm

    1:01 they have been hiring quants for hft trading (huuuuge amount of trades in a second swollowing all liquidity from different stocks) using ticks (not 1 min, 5 min 15 min, 30 min, hour, day time frames) in veeeeeeery veeeeeery small timeframes..

  • Даниил Устименко March 9, 2018 at 3:20 pm

    0:32 "if they go down u lose profits" and this is actually not true..
    if they go down, u also can own some profits and this is called SHORT position)

  • arsnakeheart March 9, 2018 at 3:20 pm

    "if you work at Google you do get free lunch"

    Someone is still paying so it's not free

  • Андрей Листопадов March 9, 2018 at 3:20 pm

    Good morning everybody. The TokenGo platform enables each of us to create our own business. Entrepreneurs, the authors of startups, projects explicitly need simple to understand and launch sites for the ICO procedure, allowing easy integration with the crowd-hosting block-platform. TokenGo's ICO Landing page constructor solves this problem to the fullest. ICO authors have the flexibility to customize their site for ICO and quickly, in a few clicks, integrate it into the TokenGo web platform.

  • Bryce Chudomelka March 9, 2018 at 3:20 pm

    Siraj, PyCharm doesn't have the library for "import lstm". What alternative library should I be using? theanos_lstm? Thanks for your time.

  • Adam Goyer March 9, 2018 at 3:20 pm

    Thanks for putting this together – will continue to follow your work

  • Afri Anto March 9, 2018 at 3:20 pm

    sign up and get 60.000 satoshi/$10 dollar per day . sign up to https://www.startminer.com/1715671

  • Fernando Leao March 9, 2018 at 3:20 pm

    Are You already richier man in thw world ?

  • barba_mma March 9, 2018 at 3:20 pm

    Great video. But the data from finance.google not available(( Can you share this data, please?

  • Joseph Luce March 9, 2018 at 3:20 pm

    He is using the wrong algorithm for this problem. You need something that remembers sequences which in this case is a RNN.

  • Dylan Redmond March 9, 2018 at 3:20 pm

    how does this predict anything? all it does for me is graph the historical data??

  • vijay nirmal March 9, 2018 at 3:20 pm

    Use pandas

  • PurpleGround March 9, 2018 at 3:20 pm

    What do you use?

  • Joseph Watkins March 9, 2018 at 3:20 pm

    Brilliant use of WoWS clip! Bravo

  • Manuel March 9, 2018 at 3:20 pm

    this channel is gold. Thx bro

  • Aiyappaa A March 9, 2018 at 3:20 pm

    awesome bro … good job

  • NG7711 March 9, 2018 at 3:20 pm

    Is this challenge have a winner yet?

  • saw ezo March 9, 2018 at 3:20 pm

    my code is producing a graph that does not pass the vertical line test (basically circles around). any suggestions for fixing this? its driving me crazy

  • Mike Jacobs March 9, 2018 at 3:20 pm

    This is awesome.

  • hemant rakesh March 9, 2018 at 3:20 pm

    I don't get an output for this code. There are no errors as I'm using Sublime text editor to code this.. I have download the spreadsheet as well, but all I get is an empty python.exe window, No graphs. What might be the problem?

  • GodricThe March 9, 2018 at 3:20 pm

    snake oil i see

  • laxman banoth March 9, 2018 at 3:20 pm

    Machine learning using python programming mainly supervised learning example plz

  • laxman banoth March 9, 2018 at 3:20 pm

    Supervised learning example plz

  • Quant-O-Tron Channel March 9, 2018 at 3:20 pm

    Please publish what you think Snapchat's IPO price will be! 🙂

  • contenau22 March 9, 2018 at 3:20 pm

    5:39 thats actually breakfast

  • Phi Hoang March 9, 2018 at 3:20 pm

    I want to learn to code.
    Where do I start?

  • Anthony Meszaros March 9, 2018 at 3:20 pm

    crazy stuff

  • Klin-Klin March 9, 2018 at 3:20 pm

    I suspect accurate market prediction would change it's outcome, making it inaccurate in the end) One would have to consider consequences of selling or buying in anticipation of predicted dive/hike, possibly causing rapid bubble growth with inevitable burst, or just a total crash right away. If anything, guys down at "Wall St." would use tools to manipulate trading, actually shaping the market outcome rather than predicting it. Such software would also have to counter anything unusual, especially if it looks like trade anticipates its own activity (someone or something discovered a pattern)

  • BOT Spoderman March 9, 2018 at 3:20 pm

    indian ulgy cunt


Leave a Reply

Your email address will not be published. Required fields are marked *