I went through this case study of Structural Time Series Modeling in TensorFlow, but I couldn't find a way to add future values of features. I would like to add holidays effect, but when I am following these steps my holidays starts to repeat in forecast period.
Below is visualisation from case study, you can see that temperature_effect starts from begginig.
Is it possible to feed the model with actual future data?
Edit:
In my case holidays started to repeat in my forecast which does not make sense.
Just now I have found issue on github refering to this problem, there is workaround to this problem.
There is a slight fallacy in what you are asking in particular. As mentioned in my comment when predicting with a model, future data does not exist because it just hasn't happened yet. For whatever model its not possible to feed data that does not exist. However you could use an autoregressive approach as defined in the link above to feed 'future' data. A Pseudo example would be as follows:
Model 1: STS model with inputs x_in and x_future to predict y_future.
You could stack this with a secondary helper model that predicts x_future from x_in.
Model 2: Regression model with input x_in predicting x_future.
Concatenating these models will result then allow your STS model to take into account 'future' feature elements. On the other hand in your question you mention a holiday effect. You could simply add another input where you define via some if/else case if a holiday effect is active or inactive. You could also use random sampling of your holiday effect as well and it might help. To exactly help you with code/model to do what you want I'll need to have more details on your model/inputs/outputs.
In simple words, you can't work with data that doesn't exist so you either need to spoof it or get it in some other way.
The tutorial on forecasting is here:https://www.tensorflow.org/probability/examples/Structural_Time_Series_Modeling_Case_Studies_Atmospheric_CO2_and_Electricity_Demand
You only need to enter new data and parameters to predict how many results in the future.
Related
I don't have too much experience with pycaret but I'm figuring things out slowly but surely. I'm trying to figure out how to have a model predict a value, not in the data I give it but rather outside the data. For example, I have data that is ordered by date from 2020-9-30 to 2020-10-30. Once I provide the model with this data, it predicts values from 2020-9-30 to 2020-10-30, but I want it to predict 2020-10-31. I can't figure out how to make that work. Please can someone who knows how to solve this problem, if there is a solution, help me.
P.S If that was confusing, please ask me to clarify 👍 Thanks!
This is what I'm using to predict the values, asset is a 250x7 data frame. When the code runs, it prints a 250x2 data frame that is an exact copy of the asset data. But I want it to print one new value in the label column
modelpredict = predict_model(final_bestmodel, data=asset)
mpdf = pd.DataFrame(modelpredict, columns = ['Date', 'Label'])
mpdf
If you do classification or regression you can use predict_model(best_model, data=data_unseen) and pass new data to the data argument e.g. if you want to prediction value on 2020-10-31 you need to provide all variables that you use in the training phase to model. You can find documentation from here and tutorial from here
If you do forecasting you can also use predict_model(best_model, fh = 24) and pass the number of forecasting horizons to fh argument, and don't forget to finalize the model before the last prediction. It will forecast fh step beyond the latest date in training data. You can find documentation from here and tutorial from here
First of all, I would like to create a recommender system. With the help of a neural network, this is supposed to make a prediction of which articles user X is most likely to buy.
I have already trained a model with the right datasets and the help of the neuMF model (you can also look at the different layers in the picture).
[Source https://arxiv.org/abs/1708.05031]
My dataset contains the following:
The column event contains whether the user has looked at an item (view), placed it in the shopping cart (addtocart) or bought it (transaction).
I have already found example implementations of how they determine the recommendations. The following was written about it:
Now that I've trained my model, I'm ready to recommend songs for a
given playlist! However, one issue that I encountered (see below) is
that I need the embedding of that new playlist (as stored in my model)
in order to find the closest relevant playlists in that embedding
space using kmeans. I am not sure how to get around this issue- as is,
it seems that I have to retrain my whole model each time I get an
input playlist in order to get that playlist embedding. Therefore, I
just test my model on a randomly chosen playlist (which happens to be
rock and oldies, mostly!) from the training set.
To recommend songs, I first cluster the learned embeddings for all of
the training playlists, and then select "neighbor" playlists for my
given test playlist as all of the other playlists in that same
cluster. I then take all of the tracks from these playlists and feed
the test playlist embedding and these "neighboring" tracks into my
model for prediction. This ranks the "neighboring" tracks by how
likely they are (under my model) to occur next in the given test
playlist.
[Source https://github.com/caravanuden/spotify_recsys]
I've just trained my model and now I'd like to make a recommendation as to which items User X is most likely to buy.
Do I have to carry out another implementation of an algorithm that determines, for example, the nearest neighbors (knn) or is it sufficient to train the model and then derive the data from it?
How do I proceed after I have trained the model with the data, how do I get the recommendations from it? What is state of the art in this area in order to receive the recommendations from the trained model?
Thanks in advance. Looking forward to suggestions, ideas and answers.
It depends on your use case for the model. This is twofold, firstly because of the performance (speed) required for your specific use case, and secondly in regards to the main weakness (in my opinion) with the neuMF model: if a user interacts with some more items, the predictions will not change, since they were not part of the training. Because of this, if it is used in an real-time-online setting, the recommendations will essentially be based on previous behavior, and will not take into account the current session, unless the model is retrained.
The neuMF model is particularly good at batch predictions for interval recommendations. If you, for example, would like to recommend items to users in a weekly email, then you would for each user, predict the output probability for each item, and then select top n (eg. 10) probabilities and recommend those. (You would have to retrain the model next week, in order to get other predictions based on the users' latest item interactions.) So if there are 10000 unique items, for each user, make 10000 individual predictions, and recommend n-items based on those. The main drawback is of course that these 10000 predictions takes a while to perform. Because of this, it might not be suitable for real-time online predictions. On the other hand, if you are clever with parallelization of the predictions, this limitation could be surpassed as well, although, might be unnecessary. This because, as explained previously, the predictions will not change depending on current user interactions.
Using knn to cluster users in the embedding-space, and then take these users' items, and feed them into the model seems unnecessary, and in my option, defeats the purpose of the whole model-architecture. This because the whole point of the neuMF model is to generalize a given user's interaction with items among all the other users' interaction, and base the recommendations on that, so that you can, given a user and an item, get the probability for that specific item.
I'm working with a company on a project to develop ML models for predictive maintenance. The data we have is a collection of log files. In each log file we have time series from sensors (Temperature, Pressure, MototSpeed,...) and a variable in which we record the faults occurred. The aim here is to build a model that will use the log files as its input (the time series) and to predict whether there will be a failure or not. For this I have some questions:
1) What is the best model capable of doing this?
2) What is the solution to deal with imbalanced data? In fact, for some kind of failures we don't have enough data.
I tried to construct an RNN classifier using LSTM after transforming the time series to sub time series of a fixed length. The targets were 1 if there was a fault and 0 if not. The number of ones compared to the number of zeros is negligible. As a result, the model always predicted 0. What is the solution?
Mohamed, for this problem you could actually start with traditional ML models (random forest, lightGBM, or anything of this nature). I recommend you focus on your features. For example you mentioned Pressure, MototSpeed. Look at some window of time going back. Calculate moving averages, min/max values in that same window, st.dev. To tackle this problem you will need to have a set of healthy features. Take a look at featuretools package. You can either use it or get some ideas what features can be created using time series data. Back to your questions.
1) What is the best model capable of doing this? Traditional ML methods as mentioned above. You could also use deep learning models, but I would first start with easy models. Also if you do not have a lot of data I probably would not touch RNN models.
2) What is the solution to deal with imbalanced data? You may want to oversample or undersample your data. For oversampling look at the SMOTE package.
Good luck
I want to predict company's sales. I tried with LSTM but all the examples that I found only use two variables (time and sales).
https://www.kaggle.com/freespirit08/time-series-for-beginners-with-arima
This page mentioned that time series only use two variables but I think that is not suficient to build a good forecast. After this, I found different 'multiple features' options like polynomial regression with PolynomialFeatures from sklearn or regression trees. I haven't write a script with these last algorithms yet, then I wanna know your recommendations about what model to use.
Thanks.
You could try Facebook's Prophet, which allows you to take into account additional regressors, or Amazon's DeepAR.
But I also have seen forecasting models based not on ARIMA style time series but on simple linear regression with extensive feature engineering (features=store+product+historical values) in production.
Hope this helps.
I would recommend using Prophet. As this has certain advantages over conventional models like ARIMA:
It take cares of empty value well.
Tunning its parameters is way easier and intuition based.
Traditional time series forecasting model expects data points to be in consistent time interval. However, that’s not the case with “Prophet”. Time interval need not to be same throughout.
This might sound silly but I'm just wondering about the possibility of modifying a neural network to obtain a probability density function rather than a single value when you are trying to predict a scalar. I know that when you are trying to classify images or words you can get a probability for each class, so I'm thinking there might be a way to do something similar with a continuous value and plot it. (Similar to the posterior plot with bayesian optimisation)
Such details could be interesting when deploying a model for prediction and could provide more flexibility than a single value.
Does anyone knows a way to obtain such an output?
Thanks!
Ok So I found a solution to this issue, though it adds a lot of overhead.
Initially I thought the keras callback could be of use but despite the fact that it provided the flexibility that I wanted i.e.: train only on test data or only a subset and not for every test. It seems that callbacks are only given summary data from the logs.
So the first step what to create a custom metric that would do the same calculation as any metric with the 2 arrays ( the true value and the predicted value) and once those calculations are done, output them to a file for later use.
Then once we found a way to gather all the data for every sample, the next step was to implement a method that could give a good measure of error. I'm currently implementing a handful of methods but the most fitting one seem to be bayesian bootstraping ( user lmc2179 has a great python implementation). I also implemented ensemble methods and gaussian process as alternatives or to use as other metrics and some other bayesian methods.
I'll try to find if there are internals in keras that are set during the training and testing phases to see if I can set a trigger for my metric. The main issue with using all the data is that you obtain a lot of unreliable data points at the start since the network is not optimized. Some data filtering could be useful to remove a good amount of those points to improve the results of the error predictors.
I'll update if I find anything interesting.