• Home
  • AI

Predicting Stock Prices – Learn Python for Data Science #4

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:

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:
Facebook: Instagram: Instagram:
Signup for my newsletter for exciting updates in the field of AI:

Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available):

Joe Lilli
 

  • @robertnewton7263 says:

    You are awesome man! I watched every video and it has motivated me to learn these programs. I might even do a blog about it! Keep it up!

  • @jackeown says:

    Isn’t this just overfitting? at 6:24 you can see that you’ve trained on the variables dates and prices and then also use them as your testing data…or is there something I’m missing?

    • @YouTouchinside says:

      You are absolutely right

    • @SirajRaval says:

      the graph fits to the training data, i don’t plot predicted points but you can print predicted data points to command line using the 2nd helper function.

    • @jackeown says:

      Thanks! I don’t mean to nitpick, but what is your performance on data points outside of the date range upon which you trained?

    • @Loserfr says:

      Doesn’t that depends on the time and resources associated with the training?

    • @ailabsus says:

      Seems like Siraj was trying to apply this model for different set for test and could not, after decided to just overfit. Anyway, find his videos very useful. Thanks, Siraj!

  • @deepschoolai says:

    pandas, pd.read_csv would probably make reading the csv alot faster/ easier.

    • @SirajRaval says:

      tru tru

    • @pascal6094 says:

      @The Math Student How do you write this in a program with pandas?

    • @lucasscoppio4195 says:

      df = pd.read_csv(filename)

      dates = df.index.values
      price = df[‘price’].values

    • @ayush328 says:

      The Math Student how prediction is done for 2018 year?? I mean what are values for input node ??

    • @fabian8813 says:

      Cheers for this, I’ve been looking for “stock market outlook tomorrow” for a while now, and I think this has helped. Have you ever come across – Sanames Stockify Scripophily – (just google it ) ? Ive heard some unbelievable things about it and my friend got excellent results with it.

  • @rameshramachandran698 says:

    This is a toy example. To build a system that works you would need to use Deep Reinforcement learning. And approach the stock market similar to playing a game. The system should be able to identify Good Risk to Reward setups and continuously monitor price action to ascertain whether the odds have changed. It is not enough to just predict the price action. The system should provide a good entry price a stop loss price and a profit exit price.

    • @SirajRaval says:

      good point thanks Ramesh

    • @washfi says:

      lol…. this model is all bulls hit…. common sense… make money….. the idea is very simple dear..you don’t need 180 IQ to make make money in stock market nor you need any fancy financial model… these are all look Gud and seems interesting. The truth is that any dumb guy can make money in stock market… timing is impossible… it is time in the market and holding period that matters… quarter to quarter earning and reporting don’t works… rest is the history…

    • @bluebull399 says:

      A good trader can just look at a naked chart and if he sees recurring patterns he knows he has a high probability of winning. This talent alone requires no math and often I see bad traders get bogged down in math, algorithms and indicators when in reality you your brain does it all for you without even thinking about it. Just look at a chart and watch the patterns appear before your eyes.

    • @arthurmwai3728 says:

      Very true. Price action trading is the way to go: watch out for candlestick patterns and make your trade based on a risk:reward ratio with stopLoss and takeProfit

    • @plexm6060 says:

      I’ve seen a team from a top uni using something based on rnn to do this and the project last for a year. Their best effort was around 60%~70% in next day accuracy in first 5 months and 40% or less in the rest months. Overall it was not better than tossing a coin or even worse. Because it was “garbage in garbage out”, and no one is able to ( or it is not worth to, compared to other profiting methods) get the genuine features of stocking market. However, there is a company using semantic analysis to read news to get a firm’s status and ultimately making a bigger profit. But in this story the determiner is still human.

  • @ed6937 says:

    Here comes my code for the challenge:
    https://github.com/ciurana2016/predict_stock_py

    Man great videos, but the dificulty of this series is growing exponentially hard. First video: im going to teach you list, strings etc, this video: build a neural network XD. I need no NN to predict that in video 8 you are going to teach us how to travel in time or something like that. I love the series anyway!! I’ll do the challenges every week !!

    • @SirajRaval says:

      LMAO. this comment had me burst out laughing for a while. you are right. im very impatient. i’ll get better at it thanks Victor.

    • @ayush328 says:

      Victor Ciurana how prediction is done for 2018 year?? I mean what are values for input node ??

    • @manudelmarche says:

      well if we learn how to travel in time, the subject of this video will be void 🙂

    • @systinfo609 says:

      Hey how do you run the predict_stock.py
      When I run that code with python predict_stock.py
      There’s an error if missing padentheses in call to ‘ print ‘

      If I run it with python2 the error is no module tweepy and other

      How do you fix that?

    • @jantube358 says:

      Yes man! It could be 10-20 episodes instead of 6 in this playlist! It would be so helpful. I am already confused with the “Gradient Descent Alorithm” from the last episode. Do I have to understand that to move on?

  • @Mosfet510 says:

    This is a great channel, just what I was looking for. You have a good way of bringing someone up to speed fast.

  • @faiyaadalam1664 says:

    Perfect! You go at a really good pace. Thanks a lot for the knowledge dump.

  • @transam351 says:

    You are amazing!!!! Thanks so much for taking the time to do this

  • @pasanpawan1834 says:

    Man, you break this down soo much better than other machine learning videos 🙂

  • @KingpinRonin says:

    this is a video on learning code, not making money. the choice of the stock market as a subject is just a tool to create interest in the real subject of the video: coding ideas. I don’t understand how people are so irate in this comments section about this. If the poster, or anybody, made real money with 40 lines of code… none of you would be posting here arguing about it, you’d be making money with 40 lines of code you found on a YT video. the stock market is just the frame for the idea.

    • @michaelheery7427 says:

      Aleays remember ITS GAMBLING…

    • @philippedeleersnyder1232 says:

      It is really blissful to share great opportunities like this. I never thought i would make it this far in just weeks with just trading and i give accolades to Iqd momentum Forex strategy. I was referred to the author Lukasz Wilhelm only in December of last year after watching series of Siraj Raval wonderful videos on youtube and my life has changed so much since then. Thank you Man
      .

    • @informativecontent4778 says:

      Fuckoff

  • @jonstuartjon3 says:

    Just want to thank you, Siraj. Your videos are amazing…They’re changing lives, for sure. Best of luck to you, and thanks again.

  • @Ninja-iq2xt says:

    I thought these short length videos wont explain much, but am amazed this is as effective as a 20min. video tutorial. you got one more subscriber! 😉

  • @shubhigautam9655 says:

    Really love your videos! I started watching them last night, and can’t stop. Although you’re a bit fast, I think it actually helps us focus on the things you say/ catch our own mistakes as we code. Great job Siraj! 🙂 Please keep uploading more videos haha

  • @NishaThomp93 says:

    Does csv file reader still work? My terminal keeps getting stuck on not having a mod named csvFileReader. I went into the folder all I have is csv.py in there. I tried trying just csv in place of cfr but I’m still getting errors.

  • @adamgoyer2077 says:

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

  • @adnanqz4974 says:

    Amazing video! Going to use this example in a workshop I’m conducting for business school students this week! Will remember to cite you during the workshop and ask them to check out your channel. Cheers!

  • @ytcio says:

    It’s just regression, not prediction

    • @scotta8612 says:

      shhh don’t tell the masses

    • @sescalaster says:

      Exactly. Any intro statistics course will tell you regression models help you make predictions for values within the range of your independent variables. Predicting outside this range is extrapolating the model and it has significantly higher risk. I wouldn’t necessarily go for it to stack ‘dem benjamins.

    • @scotta8612 says:

      @@sescalaster nobody gonna be stacking benjamins with a simple regression model with none of the underlying variables taken into account hahaha it’s ludicrous

    • @1HourBule says:

      This guy is a poser if you look into his code base o. Github his coding is garbage and most of his stuff is incomplete or doesn’t work

    • @carlosbustos3568 says:

      @@sescalaster
      Hey sergio
      Quick question
      Im intersted in math & using data to predict the future.
      Do you think a data analyst is a good carrer choice?
      Thank you anyone who can give me clarity

  • @williamdixon3135 says:

    I loved the wolf’s reference LMAO

  • @vedankgoyal1706 says:

    This was just regression.
    One can’t just use regression to “predict” stock prices as everyday the parameters involved are changing.
    Stock prices prediction involves a lot of different statistical concepts like Brownian Motion, Random Walk etc.
    There are different models in finance like Black-Scholes equation, Monte Carlo Simulation etc. which take into account these parameters.
    You have to know a decent amount of math to build a stock prediction algorithm

    • @sorvex9 says:

      lmfao, even if you know a ‘decent amount of math’ you still can’t predict stock prices. If you can’t predict human behaviour, you can’t predict stock prices. Period. What you can use math for, is to capture very short-term trends and buy/sell in very high frequencies using a computer.

  • @rushikeshdhamecha9482 says:

    Dude, the way you explain the things… easily and with fun. The best teacher ever I know. Thank you for these amazing video lessons.

  • >