Predict Sales Using a Neural Network (PyTorch, Google Colab)

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ต.ค. 2024
  • In this free tutorial, you will build your first neural network from scratch! You will be developing your project by coding in Python and using the popular deep learning library PyTorch. You will complete this tutorial using Google Colab so no environment or setup is needed to get started. You will be analyzing a synthetic dataset from a fictional lemonade stand and train your neural network to predict future sales.
    Follow along the tutorial here:
    www.leaky.ai/p...
    If you get stuck, you can compare your code to the solution which you can find here:
    colab.research...
    Sign up for our A.I. Trends and Free Tutorials Email List
    www.leaky.ai/s...
    Checkout our complete Introduction to A.I. Programming Course here:
    www.leaky.ai/i...
    #pytorch #python #deeplearning #colab #artificialintelligence #machinelearning

ความคิดเห็น • 34

  • @astik2002
    @astik2002 ปีที่แล้ว +2

    Sir please start uploading more of Neural Network, your explanation of concepts is so crystal!

    • @leakyai
      @leakyai  10 หลายเดือนก่อน

      Thank you so much for your kind words, we are working on new content and hope to release more soon. Happy learning!

  • @user-lf4es6yg9p
    @user-lf4es6yg9p ปีที่แล้ว +3

    Ive been trying to learn PyTorch for a while, but all the other videos only show you crazy functions that I cant even understand what they do... Best tutorial so far. You made it simple for me. Divided things into small parts, made an example that people can also do while watching. Thanks brother!

    • @leakyai
      @leakyai  ปีที่แล้ว

      Thank you so much for your kind words and feedback! Yea, PyTorch can be tough to learn so I try to take a more simplified step-by-step approach to teaching. There are also more tutorials on the website: www.leaky.ai/ PyTorch Dataloaders, for example, are very powerful and heavily used when building PyTorch projects. You can checkout the Dataloader tutorial to get started as a next step (www.leaky.ai/dataloader). Have a great day!

  • @codes4926
    @codes4926 2 ปีที่แล้ว +3

    This must be the 'cleanest' tutorial i have seen in ML/ DS

    • @leakyai
      @leakyai  2 ปีที่แล้ว

      Thank you so much for your feedback!

  • @RelaxLofiSonataOneMusic
    @RelaxLofiSonataOneMusic ปีที่แล้ว +4

    Hello, thank you so much for your content. Before I saw your video, I watched about 8-10 videos on creating AI on PyTorch. Still, only you could explain everything qualitatively and I finally started at least something in this understanding + I liked the interaction system with you, when I had to fill in small parts of the code, and you explained these parts.
    PS I hope you can become more popular in the future. you make lessons more valuable than lessons from videos with 1-2 million views.

    • @leakyai
      @leakyai  ปีที่แล้ว

      Thank you so much for your kind words, we are absolutely thrilled that you were able to benefit from the tutorial! We hope to have more videos available soon and you can also find additional tutorials on the website (www.leaky.ai). Have a wonderful day and good luck with your A.I. journey!

  • @mrespinosa7479
    @mrespinosa7479 2 ปีที่แล้ว +3

    Thank you soo much for the video its extremelly well explained, it helped me soo much

    • @leakyai
      @leakyai  2 ปีที่แล้ว

      Thank you so much for letting me know! So glad you found it helpful! If there are other topics you would like, please do send them over as it will help us prioritize the content!

  • @KatalinPal
    @KatalinPal ปีที่แล้ว +2

    Hi, The video is clear until you use a synthetic data generator formula. How did you come up with the following conclusion:
    if weekend:
    numlemonssold = (sunny*5 + int(500 / price))
    if bigsign:
    numlemonssold = 1.3 * numlemonssold
    if warm:
    numlemonssold = 2 * numlemonssold
    if sunny:
    numlemonssold = 1.25 * numlemonssold
    numlemonssold = int(numlemonssold)

    • @leakyai
      @leakyai  ปีที่แล้ว

      Dear Katalin, in this beginner tutorial you are using a very simple synthetic dataset which allows you to focus instead on building and training of a simple neural network. The code creates the dataset using a simple formula to make it easy for the neural network to learn from the data and start making predictions. In the course (find it on leaky.ai), you will tackle real world datasets which require a lot more upfront work before you can use them with neural networks (cleaning, standardizing values, dealing with empty fields, non-linearities etc.). You will learn those techniques in the course and also how to build more advanced neural networks that can tackle real world, complex datasets.

  • @lipeemacao1348
    @lipeemacao1348 ปีที่แล้ว +2

    Amazing video thanks a lot

    • @leakyai
      @leakyai  ปีที่แล้ว

      Glad you liked it!

  • @imMonYH
    @imMonYH ปีที่แล้ว +4

    Hello , im applying these steps to a different data set and i reached the point where i calculate the totalLosstime and i get printed NaN, what is the problem

    • @leakyai
      @leakyai  ปีที่แล้ว +1

      Hey Mazin, that is great that you are trying to apply this to a new dataset! Keep in mind, the model is very simple here and therefore will usually work with limited and simple datasets. In general, NaN values can come from different sources including your new dataset (inputs) but also the gradient calculations that are calculated during training potentially. Try to simplify the dataset itself and see if it eliminates the issue. If the issue is not the dataset, you can try to reduce the training loop to one iteration and then experiment with the model size/shape itself (adding additional layers and possibly broadening the width of the layers). Once you have eliminated the NaN, you can then gradually bring back the other components of the dataset and also increase your training iterations. Hope that helps!

    • @sohanzz
      @sohanzz ปีที่แล้ว +1

      @@leakyai i am using your dataset, and still getting Total Loss: nan
      How can i fix the issue?

    • @mikevick707
      @mikevick707 ปีที่แล้ว

      @@sohanzz Yea I have the same problem. I am using a different dataset and get Nan as total loss as well

    • @fredericnicholson80
      @fredericnicholson80 10 หลายเดือนก่อน

      NaN is the python code for 'Not a Number' so somewhere in the calculation it becomes something different. check the type by using "Type(variable)", then you can backtrack where the error comes from.

  • @jousheinfo5052
    @jousheinfo5052 ปีที่แล้ว +1

    Hi, thank you for the video. I noticed you did not split the data into train and test data, maybe because you know the linear relashipship between X and Y. I am trying to build a NN, but I do not get good results. Could you please tell me how to split the data into train and test using PyTorch? Thank you!

    • @leakyai
      @leakyai  ปีที่แล้ว

      Great question, yes indeed you should always break up your data into at least a training and a test dataset (usually, we also use a validation set). We cover a lot of this in the hands-on course itself: www.leaky.ai/introduction-to-ai-programming-with-pytorch-course-beginner
      How you do this will depend a bit on how your your data is structured. A simple approach uses Python slicing:
      # Assume you have a dataset split into x (input) and y (output/label)
      import numpy as np
      # Build a list of indices and shuffle them randomly
      indices = list(range(len(x)))
      np.random.shuffle(indices)
      # Allocate 80% of the data for the training set
      trainingPercent = .8
      split = int(total*trainingPercent)
      # Now simply slice the dataset into train and validation
      train_set = Dataset(x[indices[:split]], y[indices[:split]])
      test_set = Dataset(x[indices[split:]], y[indices[split:]])
      You can also use sklearn, they have a great function that does this for you: from sklearn.model_selection import train_test_split
      You can find a good example of how to use it here: towardsdatascience.com/how-to-split-data-into-three-sets-train-validation-and-test-and-why-e50d22d3e54c

  • @Amandaaaaaa123
    @Amandaaaaaa123 ปีที่แล้ว +1

    Hey when I got to the part #Train our network a using the entire dataset 5 times, why is my Total Loss NaN?

    • @leakyai
      @leakyai  10 หลายเดือนก่อน

      Hi, there could be a couple of reasons you are getting NaN (Not a Number). Try to check your code vs the solution which you can find here: colab.research.google.com/github/LeakyAI/FirstNeuralNet/blob/main/FirstNeuralNetworkSolution.ipynb

  • @anonymous4383
    @anonymous4383 2 หลายเดือนก่อน

    Crystal here❤

  • @nayanuranggarahayu-6945
    @nayanuranggarahayu-6945 ปีที่แล้ว +1

    Hello sir. i am trying to make model using ANN on excel. but i am little bit confused how to forecast or predict the future based on the model. i tried to forecast with some scenarios using the weight that i got, but the result was 1 in maximum and 0 in minimum cause the sigmoid activation. In my understanding forecasting is to predict future.
    thanks

    • @leakyai
      @leakyai  ปีที่แล้ว

      Hi, there are a lot of components to make an effective ANN using tabular data from sources like excel. First, you must have enough data so the model is able to properly train. There must be a correlation between the inputs and desired forecasted variable for the model to train properly. Normally, if you are building a model that predicts a value (regression), you do not want to have an activation function (sigmoid, tanh etc.) in the last layer so the model is free to predict a value and not be constrained. However, if your model is used for classification instead (for example, sentiment analysis or predicting TRUE/FALSE etc.) then a sigmoid activation function would be appropriate in the last layer.

  • @hiwhyai
    @hiwhyai ปีที่แล้ว +1

    I found this error [ RuntimeError: both arguments to matmul need to be at least 1D, but they are 0D and 2D ] when i run this code [ import torch.optim as optim
    criterion = torch.nn.MSELoss()
    optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
    for epoch in range(5):
    totalLoss = 0
    for i in range(len(x)):
    y_pred = model(x[i])
    loss = criterion(y_pred, y[i])
    totalLoss+=loss.item()
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    print("Total loss", totalLoss)

    • @leakyai
      @leakyai  ปีที่แล้ว

      Dear Hiwhy, this portion of your code here looks ok to me, your error could be up earlier in your project and and likely happening around the definition of x and y. If you could send me the entire project code I would be happy to take a further look.

  • @learn_techie
    @learn_techie ปีที่แล้ว

    if we want to group for health diagnostic - for example certain medicine is effect in 1

    • @leakyai
      @leakyai  ปีที่แล้ว

      Hi, it will depend a lot on your data. If your data is naturally unlabeled, then you will want to choose an unsupervised approach and kmeans is a great start. It will cluster results it believes to be similar. Lots of parameters can be specified for kmeans. In this tutorial, the neural network is taking in labeled data (input data + number of lemonades sold as the label) so we are using a supervised approach. In this case, we train a simple neural network where we submit several known example combinations (inputs + number lemonades as the label) for the neural network to train on. If you have data similar to this (ie, known inputs and associated outputs), then you can opt to try to model with a neural network in a similar fashion. If your label is not regression (as with number of lemonades in this case), you can also convert the network instead to predict classes (classification) using a similar approach. Hope that helps!

  • @jerrys_milk
    @jerrys_milk ปีที่แล้ว

    Hi! Nice tutorial, it was a lot of help. But I have one quick question. The following error arose when running "loss = criterion(ypred, y[i])". Do you have any idea why this happened?
    AttributeError Traceback (most recent call last)
    in ()
    16
    17 # Measure how well the model predicted vs actual
    ---> 18 loss = criterion(ypred, y[i])
    19
    20 # Track how well the model predicted
    2 frames
    /usr/local/lib/python3.10/site-packages/torch/nn/functional.py in mse_loss(input, target, size_average, reduce, reduction)
    3279 mse_loss, (input, target), input, target, size_average=size_average, reduce=reduce, reduction=reduction
    3280 )
    -> 3281 if not (target.size() == input.size()):
    3282 warnings.warn(
    3283 "Using a target size ({}) that is different to the input size ({}). "
    AttributeError: 'list' object has no attribute 'size'

    • @jerrys_milk
      @jerrys_milk ปีที่แล้ว

      I am using torch version 1.13.1

    • @leakyai
      @leakyai  ปีที่แล้ว

      Hi! Looks like the inputs/outputs might be mis-aligned for some reason, could you check that you have the following code when creating the input variable x and output/label variable y?
      # Create our PyTorch tensors and move to CPU or GPU if available
      # Extract the inputs and create a PyTorch tensor x (inputs)
      inputs = ['Weekend','Sunny','Warm','BigSign','Price']
      x = torch.tensor(df[inputs].values,dtype=torch.float, device=device)
      # Extract the outputs and create a PyTorch tensor y (outputs)
      outputs = ['NumberSold']
      y = torch.tensor(df[outputs].values,dtype=torch.float, device=device)

    • @leakyai
      @leakyai  ปีที่แล้ว

      You can also check your code vs the solution posted here: github.com/LeakyAI/FirstNeuralNet/blob/main/FirstNeuralNetworkSolution.ipynb