-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data source, SMA calculation and Y outputs offsets #4
Comments
Hi, thanks for checking out the project. Let's discuss each of these points. Improvements: Data selectionGreat suggestion, I have changed it to pull from these APIs:
Maybe not correct: Calculation of the SMA + Maybe issue: Where do you offset your Y results?I just did some checks by putting
For
For
So what is happening was, it averages the 5 values, Am I correct? Did I answer your question? Or did I make a mistake? Question: Model
Hope these are useful, we can discuss more. |
Hi Thanks for answering! DataAwesome. Glad it worked. I hope it helps. AverageI just did a test and it does give the average. Apologies for that. For some reason I can't wrap my head around why it's working ha :) I usually use const calculateAverage = (quotes = [89.19,86,91.12]) => {
return quotes.reduce((total, num) => total + sum) / quotes.length
} Shifting the YsMaybe I need clarify this question. Using your example above for the data:
I'm not seeing where you set the future value, right now I think you are saying const X = [
{timestamp: "1999-11-12", price: 89.19},
{timestamp: "1999-11-19", price: 86},
{timestamp: "1999-11-26", price: 91.12},
{timestamp: "1999-12-03", price: 96.12},
{timestamp: "1999-12-10", price: 93.87}
]
const Y = 91.26. // <= The actual average for that period X If that is correct, it would mean that your ModelYes, I think adding it to your article would be great! Thanks again. |
oh also, relating to the model, I was thinking the const normalizedInputs = xs.sub(inputMin).div(inputMax.sub(inputMin))
const normalizedOutputs = ys.sub(outputMin).div(outputMax.sub(outputMin)) In plain normal JS, would look like this: const normalize = (value, min, max) => {
if (min === undefined || max === undefined) {
return value
}
return (value - min) / (max - min)
} |
Oh yes, I got your question on the Shifting the Ys now. I just checked these: By logging line 97:
And looking at line 190:
So yes, you are right that the model is calculating the average, and the aim is to predict the future SMA. So means that predicting the next point is "pointless", but predicting the next 10 points (or how far you wanna go) will be more helpful so you are predicting if it's going up and down next (and by how much). Also using SMA is possibly the easiest one to understand (for learning), that's why it was chosen in the tutorial. Alternatively, we could also, as you have suggested, shift the Y, predict the next SMA instead of the current, so it makes a bit more sense, and not just computing the average. In short, there are a few better solutions:
What do you think? Make sense? I would love to see what you have done and hope you can do a PR on the cool things you've done. |
You never actually use |
Thanks @brandonculver for highlighting that. That must be a bug. Feel free to reply here if you have fixed it or do a PR. |
You may need to have a look to this one https://github.com/tomtom94/stockmarketpredictions |
Hello,
First of all, thank you for great tutorial. And sorry for the long post.
Was reading through the code and there are a couple of things I can't understand. And maybe some potential improvement ideas.
Improvements: Data selection
You are using the "price" for your calculations which I believe isn't the best value, you usually want an "Adjusted" (aka Adj) value. When you look at the stock prices for Apple (AAPL) for example, they did a stock split about 1-2 months ago (and end of 2014) and you can see in the data that it has a huge drop in "price" because it was split (ex: 1 share now became 2 shares)...so the results won't be correct. I would advise to use Adj Close or similar. Tesla also recently did a split.
(FYI: I ended up using Yahoo finance to get data that was Adj in my model)
Maybe not correct: Calculation of the SMA
I was looking at your ComputeSMA
I might be reading the code wrong but in
curr_avg += data[k]['price'] / window_size
you are dividing theprice
by thewindow_size
before adding it to the average. Ex:Maybe issue: Where do you offset your Y results?
As I was reading your
ComputeSMA
, it seems like theset
is theavg
. Once again I might be wrong, but here are my thoughts. In youronClickTrainModel
, you haveSo it is taking the direct output from your
ComputeSMA
I believe. Now, when we look at yourComputeSMA
again, your average is calculated like so:So it's taking the values from
i
tot
which isi+window_size
(so:i
toi+window_size
) to calculate theavg
, and your set is alsodata.slice(i, i + window_size)
. So I'm not sure where you are offsetting your Y values for your model.Question: Model
Any chance you can explain in more details how you build your model?
Some examples, are:
input_layer_neurons = 100
? What does it change?const rnn_input_layer_features = 10
.div(tf.scalar(10))
do on your tensors? Does it normalize the data?Any help much appreciated.
The text was updated successfully, but these errors were encountered: