Python ML #08: Sales Forecast Tutorial with Linear Regression Model

Sdílet
Vložit
  • čas přidán 29. 08. 2024

Komentáře • 136

  • @BekBrace
    @BekBrace  Před rokem +7

    The CSV file is available for you guys to download : github.com/BekBrace/Sales-Forecast-data-csv
    The Repo Link: github.com/BekBrace/Sales-Forecast/tree/main

  • @danrobert7241
    @danrobert7241 Před 9 měsíci +12

    This is awesome! Just one quick note that you've probably caught already but around 22 minute mark you mistake the total for Feb 2013 for January. In fact January 2013's data was dropped after you created the sales_diff column and then dropped null values in the next line. January 2013 would have been null because it was the first row in the data (there would have been no value to call the difference). Anyway, not a big deal just wanted to point that out in case it tripped anyone up. Also, at 22:30 I think you meant to plot monthly_sales['sales_diff'] but you actually just re-plotted monthly sales. Regardless, still a great tutorial for figuring out the correct syntax.

    • @BekBrace
      @BekBrace  Před 3 měsíci +2

      Thank you for the kind words and for pointing that out! You're absolutely right-January 2013's data was dropped after creating the sales_diff column and dropping null values because it was the first row with no previous value to calculate the difference. Also, good catch on the plotting mistake at 22:30; it should have been monthly_sales['sales_diff'] instead of re-plotting monthly_sales. Appreciate the feedback!

  • @JanBaucke
    @JanBaucke Před rokem +5

    This is great! The methodology I was searching for to solve my problem. Thanks a lot!

  • @paulocarneiro4947
    @paulocarneiro4947 Před rokem +2

    Thank you, Bek for this nice job, helping others!

    • @BekBrace
      @BekBrace  Před rokem +1

      Thank you for your support, Paulo 🙏

  • @afolaluhelenbosede4028
    @afolaluhelenbosede4028 Před 2 lety +8

    Awesome tutorial Bek.
    Just to point out, the second plot still showed the sales trend and not sales_diff. I could notice cos I was looking out for a change in the increasing trend after you performed the sales difference.

    • @BekBrace
      @BekBrace  Před 2 lety +2

      Heyyy ! Oh that must be an error from my side , sorry for that !

    • @nwabuezeprecious457
      @nwabuezeprecious457 Před rokem

      Hi bek was the ratio of your train set and test set approximately 66:34

    • @PaulDenman
      @PaulDenman Před rokem +1

      Yup, I changed the code to:
      # Visualisation
      plt.figure(figsize=(15,5))
      plt.bar(monthly_sales['date'], monthly_sales['sales_diff'], width=12)
      plt.xlabel("Date")
      plt.ylabel("Sales")
      plt.title("Monthly Customer Sales Difference")
      plt.show()
      Notice how I changed the plot type to bar also; I prefer that vis :)

    • @PaulDenman
      @PaulDenman Před rokem

      And the Actual vs Predicted to:
      # Vis the predictions vs the actual sales
      plt.figure(figsize=(15,5))
      # Actual Sales:
      plt.bar(monthly_sales['date'], monthly_sales['sales'], width=10)
      # Actual Sales:
      plt.plot(predict_df['date'], predict_df['Linear Prediction'], color='red')
      plt.xlabel("Date")
      plt.ylabel("Sales")
      plt.title("Predictions vs Actual")
      plt.show()

    • @PaulDenman
      @PaulDenman Před rokem

      Great vid @BekBrace 😀

  • @gurtejbains
    @gurtejbains Před rokem +5

    Hi @Bek, great video.
    I see a few other people also asking the same question as mine. How can we use the fit model to predict sales for upcoming days? The sample data is at the day level so let's assume predicting daily sales for the upcoming month. Maybe you can record a new video as that will really add a lot of value.
    Thanks.

    • @BekBrace
      @BekBrace  Před rokem +4

      Hey Hey 👋 thank you
      I might create a follow-up video on this specific point / Thanks for the suggestion

    • @gurtejbains
      @gurtejbains Před rokem

      But to complete the loop and get an answer to the question in hand, do you have any recommendations for how to predict the upcoming days/weeks? Thanks again.

    • @terencedimanche
      @terencedimanche Před rokem

      @@gurtejbains Hey, I'm really interested to know how to forecast next days, months with this method as well !! Did you manage to find a solution?

    • @Silas_Wahome
      @Silas_Wahome Před rokem +1

      @@BekBrace
      Hi, @Bek Brace
      lr_model=LinearRegression()
      lr_model.fit(x_train,y_train)
      I am getting this error after putting in that code, what could be the issue
      ValueError: Found input variables with inconsistent numbers of samples: [1, 33]

    • @Vlapstone
      @Vlapstone Před rokem +1

      ​@@BekBrace Hi there mate... thanks a lot for the video, it's amazing. what about this other video to show how to make the predictions for the upcoming days... this is actually what matters as there is no sense in predicting something is already passed. You are a great teacher and pass the info clearly wed love to have this video from you continuing with the explanation, please.

  • @danielholocsi440
    @danielholocsi440 Před 7 měsíci +1

    I wish there was a tutorial for forecasting demand by items and by stores with this same dataset.

  •  Před rokem +5

    When you want to plot the sales_difference you forgot to write (at Y axis data) difference. So the plot is wrong at 23:09

  • @DevBishwasBh
    @DevBishwasBh Před 2 lety +2

    Thanks a lot Bek, I saw your video on React and Fast API (FARM Stack) in freeCodeCamp, thanks a lot for that video. I am here to request you a video on Next Js and Fast API authentication. I am really waiting for your video and reply on this topic. Have a great day :)

    • @BekBrace
      @BekBrace  Před 2 lety +1

      Thank you very much for you kind words.
      Your request is taken in consideration :)

    • @DevBishwasBh
      @DevBishwasBh Před 2 lety +1

      @@BekBrace I'll be waiting.

  • @pujeshbhardwaj4660
    @pujeshbhardwaj4660 Před 5 dny

    In your visualization of sales difference xlable as date but in ylable you took sales , I suppose it should be sales_diff, Please clarify?

  • @funwithfriends6601
    @funwithfriends6601 Před rokem +5

    Your voice is awsm

    • @BekBrace
      @BekBrace  Před rokem

      Thank you 😊

    • @Vlapstone
      @Vlapstone Před rokem

      indeed... really smooth and you know how to explain it well. Congrats... just wish you could have a video showing how to predict the upcoming sales for the next 3 months.

  • @snowturtle319
    @snowturtle319 Před 10 měsíci +1

    Awesome tutorial ! Keep the videos coming !
    I wanted to ask is these algorithms work on qualitative data for exemple what if in "store" , it's not "1" but "Amazon" for exemple ?
    Thanks !

    • @BekBrace
      @BekBrace  Před 10 měsíci +1

      Thank you very much.
      I am really not sure, if you would want to tweak in your code or not, I will find out and let you know

  • @svetlana9699
    @svetlana9699 Před 2 lety +1

    Thanks Bek! 🔥

    • @BekBrace
      @BekBrace  Před 2 lety

      Thanks a lot for the support ☺️

  • @santiagomendez1787
    @santiagomendez1787 Před 3 měsíci

    Bek Thank you for the tutorial. i have a one question. why you take 13 rows for the actual sales and not 12?

  • @SaqibAhmadca
    @SaqibAhmadca Před 8 měsíci +1

    Hi Bek, it was a great tutorial but i have question, why you calculated lr_mse, lr_mae, lr_r2 vars as you are not using them anywhere?

    • @BekBrace
      @BekBrace  Před 8 měsíci

      Salam Saqib. Thank you for watching, brother, there was supposed to be a second part for the tutorial, unfortunately I haven't had the chance to finish it, that's why. Hope you're not disappointed, and thank you for being a good friend for the channel's 🙂🙏

  • @luisalejandro9335
    @luisalejandro9335 Před rokem +4

    Hello, i'm trying to apply this for university project but i'm not sure about what the process would be to make the predictions for the following months that we don't have information, could you help me? Many thanks

    • @BekBrace
      @BekBrace  Před rokem +1

      Sure

    • @gurtejbains
      @gurtejbains Před rokem +1

      Good question Luis. @bek, any answer for how to achieve this? Use the fit model to predict sales for the upcoming quarter?

    • @anjalipakmode5716
      @anjalipakmode5716 Před rokem +1

      Same question

    • @Vlapstone
      @Vlapstone Před rokem +1

      good question mate... did you find out how to do it?

    • @moatzmaloo
      @moatzmaloo Před 3 měsíci

      You need time series analysis for this phenomena or put your values of nex quarters manually but take in your consideration extrapolation is not always perfect

  • @senzaura6786
    @senzaura6786 Před 8 měsíci +1

    Bek, I wanna ask, did you drop the 'date' and 'sales' when you make supervised _data?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      Yes, the 'date' and 'sales' columns were not used directly in the supervised data. Instead, the 'sales' column was transformed into 'sales_diff' to capture the monthly sales differences. The 'date' column was not included in the supervised data.

  • @senzaura6786
    @senzaura6786 Před 9 měsíci +1

    Hello, Bek, thank you for making this video, it helps me alot.
    But, I want to ask something. When I first create the linear regression, the time when I add x/_train and y_train to model fit. It says, "Found input varibales with inconsistent number of samples." Any clue?

    • @senzaura6786
      @senzaura6786 Před 9 měsíci +1

      I notice that when I try to look up in range 1-13, for differences sales each store each month, I got the result is different with you.

    • @BekBrace
      @BekBrace  Před 9 měsíci

      This is odd. I have got to find the time to check out the code, but please feel free to ask the friends on the channel, they might be able to answer you quicker

    • @senzaura6786
      @senzaura6786 Před 8 měsíci +1

      I try to re-run everything and re-chechk everything the found out something odd, my supervised_data for sales_diff is totally different with you. Mine start with 3130 while you even start from minus value@@BekBrace Any clue?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      I’m glad to hear the video has been helpful! Regarding the error you encountered-“Found input variables with inconsistent numbers of samples”-this typically occurs when the X_train and y_train datasets do not have the same number of rows. Here’s how you can address this issue:
      * Check Lengths: Make sure that both X_train and y_train have the same number of rows. You can check this by printing their shapes:
      print(X_train.shape)
      print(y_train.shape)
      * Synchronize Data: Ensure that during your data preparation phase, when you split the data or create features, you keep the dataset synchronized. For example, if you're creating lagged features or handling missing values, make sure each operation maintains alignment between your features (X_train) and targets (y_train).
      * Handling Missing Data: If your preprocessing steps (like calculating differences or dropping rows) introduce missing values, ensure that you handle these consistently across both feature and target datasets. For instance, if you drop rows with NaN values in X_train, do the same for y_train:
      # Assuming you've identified rows with NaNs in X_train
      X_train = X_train.dropna()
      y_train = y_train.loc[X_train.index] # Align y_train with X_train
      *Review Data Preparation: Go back and review the steps where you prepare X_train and y_train. There might be a step where the data gets out of sync, such as when splitting the data or creating features.
      By ensuring that both X_train and y_train are correctly aligned and contain the same number of samples, you should be able to resolve this error. If the issue persists, feel free to share more details about how you are preparing your datasets, and I’ll help you debug further!

  • @asmafathima7115
    @asmafathima7115 Před rokem

    Excellent tutorial! I have a couple of questions. In the graphs you presented, "Monthly Customer Sales" and "Monthly Customer Sales Difference," they appear to be identical. Shouldn't the second graph include the "Sales Difference" column instead of "Sales" on the y-axis? I apologize for the confusion, but I would greatly appreciate it if you could clarify this.

    • @BekBrace
      @BekBrace  Před rokem

      Hi, thank you so much for watching :) - Yes, and that was a mistake from my side

  • @nctkim8476
    @nctkim8476 Před rokem +2

    Hello, Bek. I trying to do like yours code but with different data and i have problem in 'the preparing supervised data' . when i run it, it all have NaN values so i have nothing (they get drop). What should i do with that problem? can you give insight?
    Btw, awesome tutorial, Bek. Thank you for sharing this with us.
    # sorry if you not understand what i am saying, english is not my first language.

    • @BekBrace
      @BekBrace  Před rokem +1

      Hey hey 👋 your English is perfect 👍 and i understand your problem. Only one thing, when you try to clean the data from NaN, what do you get ?

    • @nctkim8476
      @nctkim8476 Před rokem

      @@BekBrace i got nothing just a column name like yours.
      btw, thank you for responding

    • @Vlapstone
      @Vlapstone Před rokem

      @SHUVRO AHMED nice you replied him, otherwise he'd still be lost... do you also get the need to have the predictions for the upcoming days? as its not part of this tutorial... im kinda lost of what this is for without the prediction for the upcoming days... if you do, can you share with me?

  • @01marcosnunes
    @01marcosnunes Před rokem +1

    when i going plot the chart, i obteined an error: TypeError: float() argument must be a string or a real number, not 'Period'.
    Please, you can help me?

    • @BekBrace
      @BekBrace  Před rokem

      Sure. The error message indicates that you are trying to convert a 'Period' object to a float, which is not possible. To resolve this issue, you need to convert the 'Period' object to a numeric value before using it in your sales forecast chart, you can convert the 'Period' object to a numeric value by accessing its 'value' attribute :
      numeric_value = period.value
      Make sure to check your code and ensure that you are applying the necessary conversion where needed.

  • @am0x01
    @am0x01 Před rokem +1

    Hello,
    Can I use the same method you used here, in yearly gross production data?
    Thanks in advance

    • @BekBrace
      @BekBrace  Před rokem +1

      Yes of course you can 👍

  • @estherjokodola1187
    @estherjokodola1187 Před rokem +1

    Thank you ❤

  • @ForexPotatoe
    @ForexPotatoe Před 7 měsíci

    Please how come you are grouping by no longer using the sales store df but just monthly sales that got me confused and i suggest next time you allow the code to run so you can see what you are getting you just run it but dont see your resutlts if its what you want before moving to the next

  • @ehiztheo166
    @ehiztheo166 Před rokem +1

    Awesome video, thanks so much for putting this out. Please I’m working on a project to predict sales for 28 days for Walmart store. Is it possible to follow this code format?

    • @BekBrace
      @BekBrace  Před rokem +1

      Thanks man, I'd say yes 🙂

    • @ehiztheo166
      @ehiztheo166 Před rokem

      @@BekBrace please how do i do the foreast for just 28 days? what should i do please

    • @Vlapstone
      @Vlapstone Před rokem

      @@ehiztheo166 hi there bro... above @SHUVRO AHMED said its about the threshold for the loop, check it out and try diminishing your as he pointed. It seems @Bek Brace is too busy to reply so many questions... hehehehe

  • @sikiruyusuff1246
    @sikiruyusuff1246 Před 6 měsíci +1

    how could the sum of sales for 2013-02-01 be 459417?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      This total likely represents the aggregated sales across all stores and items for the entire month of January 2013. In data preprocessing, the dates might be shifted or labeled to reflect the period they represent, such as using the first day of the following month to indicate the total sales of the previous month. Always ensure that the date handling aligns with how your data is structured and aggregated.

  • @yuriy_mikay777
    @yuriy_mikay777 Před rokem

    Nice sample, but if I need to make predictions to 01-2019, 02-2019 … What I need to change?

  • @tf015_nihlatilmaula2
    @tf015_nihlatilmaula2 Před 4 měsíci

    just wanna add, if you face some error with this code line
    monthly_sales = store_sales.groupby('date').sum().reset_index()
    change to this
    monthly_sales = store_sales.groupby('date').agg({'sales':'sum'}).reset_index()

  • @christopherdelgado1397
    @christopherdelgado1397 Před 9 měsíci

    I have a question about how to interpret the supervised data:
    I'm following the code and getting the same data as you no errors, but I'm confused on how the supervised_data ended up with 47 rows. How do these rows represent the sales of each store number if we dropped the store number in the very start of the video????

  • @adin6429
    @adin6429 Před rokem

    First of all thanks alot for awesome tutorial.
    Could you please answer how to apply the model to predict for next year, in this case 2019?

    • @BekBrace
      @BekBrace  Před rokem +1

      I will probably create a whole video to explain that, thanks for the suggestion my friend :)

    • @user-hl4cv6tb8q
      @user-hl4cv6tb8q Před 11 měsíci

      This video is already done?@@BekBrace

  • @fidelinojuls
    @fidelinojuls Před rokem

    What changes should I imply to predict for the next 3 years?

  • @presidenthotsauce
    @presidenthotsauce Před rokem +1

    Hi Bek, could you also share the test dataset, please? Thank you.

    • @BekBrace
      @BekBrace  Před rokem

      Yeah about that, unfortunately i cannot do it for the moment 😔 but i promise to do that later today

  • @user-lw3yn7ty9y
    @user-lw3yn7ty9y Před rokem

    Hi , I have a dataset who's data - granularity is monthly and I receive data for multiple items and stores but only monthly ie 1st of each month. How can I accommodate the code accordingly and forecast shares?

  • @nelsonstropa8352
    @nelsonstropa8352 Před rokem

    I can't read the csv file,
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 17: invalid start byte
    What am i doing wrong?

    • @BekBrace
      @BekBrace  Před rokem

      Hey friend.
      This error occurs when the CSV file you're trying to read contains characters that are not in the UTF-8 character encoding, and I think one way to solve it before reading the file is as follows:
      import codecs
      with codecs.open('file.csv', 'rb', encoding='iso-8859-1') as f:
      # read the file here
      Try that and let me know

  • @shilpashingari4111
    @shilpashingari4111 Před 10 měsíci

    In splitdata into train and test:
    Coding of minmaxscaler feature range (-1,1) show error found arry with 0samplee while a minimum of 1 is requires by minmaxscaler how to fix this value error

    • @BekBrace
      @BekBrace  Před 8 měsíci

      Hey friend!
      The error you're encountering suggests that your dataset has some features with zero samples, and the HeMinMaxScaler requires at least one sample for each feature to determine the scaling parameters.
      To fix this issue, you should ensure that your dataset has at least one sample for each feature before applying the MinMaxScaler.

  • @ForexPotatoe
    @ForexPotatoe Před 7 měsíci

    i dont get the logic behind monthly_Sales =df.groupby('Date').sum().reset_index()
    monthly_Sales grouping by with month when you will later convert again to timestamp later on

    • @naren2412
      @naren2412 Před 7 měsíci

      This just gives you the total sales for a particular month ...first grouped by month and then take the sum of all the sales in that month...He changes the data type of the 'date' for the sake of time series plot .

    • @BekBrace
      @BekBrace  Před 7 měsíci

      Thank you Naren for the answer

  • @aliyilbasi8587
    @aliyilbasi8587 Před 5 měsíci

    thanks for your effort ı really appreciated, but ı stuck to figure out logic behind supervised data can someone please explain it?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      Thank you :)
      The supervised data creation is about structuring the dataset for supervised learning. We transform the time series data into a supervised learning problem by creating input-output pairs :)
      Shift the Data: We use the shift method to create lagged versions of the data. For example, if you want to predict sales based on the previous month, you shift the sales data by one month.
      Concatenate the Data: Combine these lagged features with the original data, aligning them properly to ensure each row contains the sales data for the current and previous months.
      Drop NaNs: Any rows that have NaN values (which occur because of shifting) are dropped to maintain a consistent dataset.
      This results in a dataset where each row can be used as an input-output pair for training a model. The input features are the lagged sales data, and the output is the sales for the current month.
      Here's a small code snippet to illustrate this:
      supervised_data = pd.concat([monthly_sales.shift(i) for i in range(1, n+1)], axis=1)
      supervised_data.dropna(inplace=True)
      beware my friend, n is the number of lagged months you want to use as input features.
      it's a long answer, but hopefully this cleared any mysteries for you :)

  • @fidelinojuls
    @fidelinojuls Před rokem

    Hi, Bek! How could I predict for the next months using the same methodology?

    • @BekBrace
      @BekBrace  Před rokem +3

      Good question! That may trigger a future video to explain in details

    • @Zirea.eya69
      @Zirea.eya69 Před rokem +1

      @@BekBrace i need this too Sir

  • @arshadsyed3653
    @arshadsyed3653 Před rokem

    Sir what are the accuracy percentage of this project ?? Means how the accurate is the prediction ??

    • @BekBrace
      @BekBrace  Před rokem

      Hi there.
      The accuracy of a sales forecast in this tutorial depends on various factors, including the quality and relevance of the data, the appropriateness of the assumptions made, and the complexity of the sales patterns being modeled. As you saw, I used linear regression which is a commonly used technique for sales forecasting because it provides a straightforward way to model the relationship between independent variables (e.g., time, marketing spend) and sales.
      However, the accuracy of the predictions produced by a linear regression model can vary. It is important to evaluate the model's performance using appropriate metrics such as mean squared error (MSE), mean absolute error (MAE), or R-squared (coefficient of determination). These metrics quantify the difference between the predicted sales values and the actual sales values.
      I hope this answers your question, and don't leave the channel, as soon I am going be doing Credit Card Fraud detection analysis tutorial.

  • @amanpiyushsharma
    @amanpiyushsharma Před rokem

    at 16:31 i m getting an error 'DatetimeProperties' object has no attribute 'to_timestamp'
    help me please

    • @BekBrace
      @BekBrace  Před rokem

      The error message you are seeing, "'DatetimeProperties' object has no attribute 'to_timestamp'", suggests that you are trying to use the to_timestamp method on a DatetimeProperties object, but this method is not available for that particular object.
      In Python's standard library, there is no built-in to_timestamp method for the DatetimeProperties class. However, the to_timestamp method is available for datetime objects in Python, which allows converting a datetime object to a Unix timestamp.
      If you have a DatetimeProperties object and you want to convert it to a timestamp, you can use the timestamp() method available for datetime objects.

  • @tf015_nihlatilmaula2
    @tf015_nihlatilmaula2 Před 4 měsíci

    is this code applicable for multiple linear regression?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      Yes, the code can be adapted for multiple linear regression. Multiple linear regression simply involves more input features.
      from sklearn.linear_model import LinearRegression
      import numpy as np
      # Assuming 'train_data' is your training data with multiple features
      X_train = train_data.drop('target', axis=1)
      y_train = train_data['target']
      # Initialize and train the model
      model = LinearRegression()
      model.fit(X_train, y_train)
      # Prepare the last 12 months of features for prediction
      last_12_months_features = np.array([last_12_months_data])
      # Prepare list to store predictions
      future_predictions = []
      for _ in range(12):
      # Predict next month's target
      next_month_prediction = model.predict(last_12_months_features)

      # Append the prediction to future_predictions
      future_predictions.append(next_month_prediction)

      # Update last_12_months_features for next prediction
      last_12_months_features = update_features(last_12_months_features, next_month_prediction)
      # future_predictions now contains the forecast for the next 12 months

  • @fidelinojuls
    @fidelinojuls Před rokem

    Hi! If in my dataset, I've gotten a negative R2 score what does it mean?

    • @BekBrace
      @BekBrace  Před rokem

      Hi Julian :) - well, the R-squared (R2) score is a statistical measure that indicates the proportion of the variance in the dependent variable that can be explained by the independent variables in a regression model. It ranges from 0 to 1, with higher values indicating a better fit of the model to the data.
      If you obtained a negative R2 score, it means that the regression model you used performed worse than a horizontal line (i.e., a constant model that ignores the independent variables) in explaining the variance in the dependent variable. In other words, the model's predictions are even worse than simply using the mean value of the dependent variable as a constant.

  • @archangelYtube
    @archangelYtube Před rokem

    Hi bek!how to future predict in this method?for example for next 3 or 6 months?

    • @BekBrace
      @BekBrace  Před rokem +1

      Depends

    • @Vlapstone
      @Vlapstone Před rokem

      Hi there mate... did you find out how to do it?

  • @ivankalarasati
    @ivankalarasati Před 6 měsíci

    why mine 'DataFrame' object has no attribute 'reset' how to solve it?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      The error "'DataFrame' object has no attribute 'reset'" likely occurs due to a typo. The correct method is reset_index(). Ensure you use:
      df.reset_index(drop=True)
      Double-check your DataFrame's name to avoid referencing errors.

  • @DineshR-uu8rq
    @DineshR-uu8rq Před rokem +2

    lr_mse = np.sqrt(mean_squared_error(predict_df['Linear Prediction'], monthly_sales['sales'][-12:]))
    lr_mae = mean_absolute_error(predict_df['Linear Prediction'], monthly_sales['sales'][-12:])
    lr_r2 = r2_score = (predict_df['Linear Prediction'], monthly_sales['sales'][-12:])
    print("Linear Regression MSE", lr_mse)
    print("Linear Regression MAE", lr_mae)
    print("Linear Regression R2", lr_r2)
    Bro, I have run this code but the accuracy is not displaying .
    I follow what you said to cut this specific code and give runall and again i paste and run the code it again show like that only not show the accuracy?What to do now?

    • @saloualakhdar6659
      @saloualakhdar6659 Před rokem +2

      i have the same problem as yours

    • @PaulDenman
      @PaulDenman Před rokem +1

      Hi @user-ev8cs6yw4r and @saloualakhdar6659
      You need to change this line from:
      lr_r2 = r2_score = (predict_df['Linear Prediction'], monthly_sales['sales'][-12:])
      To:
      lr_r2 = r2_score(predict_df['Linear Prediction'], monthly_sales['sales'][-12:])
      The change in the video happens at 52:24 -> 52:25, but it isn't mentioned ;)

  • @akshayshinde6641
    @akshayshinde6641 Před 4 měsíci

    How to use this model to predict 2018 forecast

    • @BekBrace
      @BekBrace  Před 3 měsíci

      # Assuming 'model' is your trained linear regression model and 'scaler' is your Min-Max scaler
      # Last 12 months sales data from 2017
      input_features = np.array([Dec_2016_sales, Jan_2017_sales, ..., Nov_2017_sales, Dec_2017_sales])
      # Scale the features as the model expects scaled input
      scaled_features = scaler.transform([input_features])
      # Make prediction
      predicted_sales_Jan_2018 = model.predict([scaled_features])
      # Inverse scale if the output was scaled
      predicted_sales_Jan_2018 = scaler.inverse_transform([predicted_sales_Jan_2018])
      # Use predicted_sales_Jan_2018 to update your dataset for the next prediction if necessary

  • @DipanSadekeen
    @DipanSadekeen Před 4 měsíci

    where can I find the code?

  • @khushbugupta6970
    @khushbugupta6970 Před 6 měsíci

    We didnt use XG Boost and Random forest as we intented first

  • @shwetalpatil4461
    @shwetalpatil4461 Před rokem +1

    Hi Nice explanation, can you give google colab file to me?

    • @BekBrace
      @BekBrace  Před rokem

      Unfortunately it was lost and didn't keep a copy of it, I'll look through my old files though and keep you posted. Thank you for watching 🙂

  • @shreyagoyal2847
    @shreyagoyal2847 Před rokem

    I am not able to download this train dataset from github, if anyone could please guide me…

    • @BekBrace
      @BekBrace  Před rokem

      Click on the file, then click view raw, then copy the data and paste it into an excel file saved under csv file extension

    • @shreyagoyal2847
      @shreyagoyal2847 Před rokem

      Done, now while writing the code, I am facing issues while downloading library for tensorflow

    • @BekBrace
      @BekBrace  Před rokem

      ​@@shreyagoyal2847what's the error ?

  • @NagaManojG
    @NagaManojG Před 3 měsíci

    collab link ?

  • @harrisjunejanani5887
    @harrisjunejanani5887 Před 5 měsíci

    can you post the codes that you are using?

  • @prashantipenumatsa8814
    @prashantipenumatsa8814 Před rokem +1

    Can you provide the total code if possible

    • @BekBrace
      @BekBrace  Před rokem +1

      Sorry, but I lost the code somehow

  • @ivankalarasati
    @ivankalarasati Před 4 měsíci

    how to predict 1 year in the future after this?

    • @BekBrace
      @BekBrace  Před 3 měsíci

      import numpy as np
      # Assuming 'model' is your trained model and 'scaler' is your Min-Max scaler
      # Last 12 months sales data
      input_features = np.array([last_12_months_sales])
      # Prepare list to store predictions
      future_predictions = []
      for _ in range(12):
      # Scale features
      scaled_features = scaler.transform([input_features])

      # Predict next month's sales
      next_month_prediction = model.predict(scaled_features)

      # Inverse scale the prediction
      next_month_sales = scaler.inverse_transform(next_month_prediction)

      # Store the prediction
      future_predictions.append(next_month_sales)

      # Update input features for next prediction
      input_features = np.append(input_features[1:], next_month_sales)
      # future_predictions now contains the sales forecast for the next 12 months

    • @ivankalarasati
      @ivankalarasati Před 2 měsíci

      @@BekBrace the result of future prediction is like that, is that true?
      ]
      0s
      future_predictions
      [array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706]),
      array([0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706,
      0.123706, 0.123706, 0.123706, 0.123706, 0.123706, 0.123706])]

  • @user-tv1ir5fc3x
    @user-tv1ir5fc3x Před 7 měsíci

    awasome sir, can I ask for the code?

  • @spitfirelast8761
    @spitfirelast8761 Před rokem +1

    How can you make this into a website feature?

    • @BekBrace
      @BekBrace  Před rokem

      that is to look in deeper, do not have a ready answer now, but i suspect it is very possible to convert the algorithms into an interactive web app for deployment