I have time series data that associates a measurement to the time. Suppose that it is an app where a user enters their height whenever they want. Based on past behavior, I not only what to predict what their next height measurement is, but I also want to predict when the measurement will be entered.
Sample data for a single person:
Date | Measurement
-------------|------------
Nov 8, 2014 | 1.42 m
Nov 23, 2014 | 1.43 m
Mar 8, 2015 | 1.48 m
Jun 15, 2015 | 1.52 m
Dec 18, 2015 | 1.52 m
Mar 1, 2016 | 1.59 m
Nov 8, 2016 | 1.60 m
What I want to predict is the next data point in this series. For example, it might be (Dec 8, 2016, 1.61 m).
My initial thoughts have been to make two separate models, one that is simply the time data with x values being indices. For example
0 | Nov 8, 2014
1 | Nov 23, 2014
2 | Mar 8, 2015
3 | Jun 15, 2015
4 | Dec 18, 2015
5 | Mar 1, 2016
6 | Nov 8, 2016
(where the dates have been converted to minutes since 1970 or something).
Use this model to predict the next time point, then the original model to predict, at that time point, what will be the measurement.
In terms of algorithms to use I was thinking to use a Kalman filter for both models.
My question is that I feel like I am missing something, or possibly over complicating this problem. Does anyone have an idea for an alternative solution?
I will be implementing in javascript with hopefully no external libraries.
Related
The issue is specific to moment.year()
I am trying to get the beginning date of the next week based on the current date. It works well except for the last month of the year. The example should explain.
new Date(moment(1577379939000).year(2020).week(1).weekday(0).format('MM/DD/YYYY'))
Sun Dec 29 2019 00:00:00 GMT-0500 (Eastern Standard Time)
This gives me Sun Dec 29 2019 00:00:00 GMT-0500 (Eastern Standard Time) 29th dec 2019 as begining of the next week(sunday)
This is correct
1577379939000 is 26th of December 2019(Thursday).
However, if the input is 1577466306000 which is 27th of December 2019(Friday)
it gives me 2020 December date, not 2019
new Date(moment(1577466306000).year(2020).week(1).weekday(0).format('MM/DD/YYYY'))
Sun Dec 27 2020 00:00:00 GMT-0500 (Eastern Standard Time)
If it is moment.js error. is there any workaround?
Try to use weekYear instead of year
I think this is working as intended. After you use .year(2020) you're changing the dates to December 2020. This is the calendary for that month:
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
In the United States, moment.js defines weeks to start on Sunday, and week 1 is the week containing January 1. So the week beginning with December 27 is actually week 1 of 2021.
That means that when you call .week(1), it doesn't change anything for December 27, and returns a date in December 2020 when you call .weekday(0).
But December 26 is in week 26 of 2020, so calling .week(1) changes the date to Saturday in week 1 of 2020, which is January 4. Then calling .weekday(0) returns the Sunday before that, which is December 29, 2019.
As mentioned in a comment, the way to get the first day of the next week after a given date, just use .weekday(7).
new Date(moment(1577466306000).weekday(7))
I'm not sure why you're specifying a particular year or week number.
I trying to implementing scheduler in web application.
I am using full calendar for scheduler ,I am showing all scheduled event on days and I have set eventLimit on day as 4.
Now I have question how can i show plus more event on other day have not any events.
Eg:
Event Start Date 13 Jan 2017 and EndDate 21 Jan 2017.
Event Start Date 16 Jan 2017 :Have 4 events. End date :18 Jan 2017.
[Note :2nd displaying 4 events with title on 16 Jan to 18 Jan]
Now 1st event start 13 Jan 2017 to 21 Jan 2017 When event goes 16 Jan 2017 then event limit do automatically plus more 1 .same continue on 17 Jan to 21 Jan 2017.
Now Question is 19 ,20 ,21 Jan 2017 have not any events then event should be displayed with title. but this kind of not happens it displaying plus more 1 on 19 ,20 ,21 Jan 2017.]
How can we show plus more event with title on the day have any events ?
thanks in Advance.
Say I have some data that can span anywhere from 28-31 days. I don't know how many days the data spans, but I know the beginning and ending date, and I create a d3 time scale using the two dates as the domain.
If I specify that I want 1 tick per day, is there a way to get the axis to return how many ticks it's going to create?
Or put another way, is there another method to determine in Javascript how many days are in a range of two dates?
Check out d3.time.day. It's what d3.time.scale uses to do "time math". It's kinda hard to figure how to use, but it looks like there's a method that'll return every day between two dates (represented as a Date object at midnight of each day).
For example, here are the days that elapsed between Jan 24th and now:
d3.time.day.range(new Date(2015,0,24), new Date())
/* returns
[
Sat Jan 24 2015 00:00:00 GMT-0500 (EST),
Sun Jan 25 2015 00:00:00 GMT-0500 (EST),
Mon Jan 26 2015 00:00:00 GMT-0500 (EST),
...
Tue Feb 03 2015 00:00:00 GMT-0500 (EST),
Wed Feb 04 2015 00:00:00 GMT-0500 (EST)
]
*/
So then you can take the .length of that array and there you have it... There are also equivalent functions for counting hours, weeks, months etc.
Maybe there's also a way to get just the number of days — without producing the actual array of Dates — but I couldn't find one.
I did create a date object out of '31/12/2018':
new Date('2018', '12', '31')
It does however create something completely different that I would expect.
Date {Thu Jan 31 2019 00:00:00 GMT+0100 (Central European Standard Time)}
What's happening?
Months are indexed starting from 0. Use 11 for December, not 12 :
new Date(2018, 11, 31)
(and yes, there should be numbers instead of strings, which makes it a little less confusing)
From the MDN :
month
Integer value representing the month, beginning with 0 for
January to 11 for December.
Months start with 0 in JavaScript. January is 0; December is 11. 12 represents January the following year. You'll want to use 11 instead of 12:
new Date('2018', '11', '31')
-> Mon Dec 31 2018 00:00:00 GMT+0100 (Central European Standard Time)
You've forget that months in JS starts with 0 instead 1.
Please use
new Date('2018', '11', '31')
in your case.
In the library D3. I find the set of functions to handle dates a bit inconsistent. For example, doing the following 4 steps in a console of a page loading D3 I get:
> start = new Date(2010, 11, 30)
Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time)
> end = new Date(2011, 0, 2)
Sun Jan 02 2011 00:00:00 GMT+0000 (GMT Standard Time)
> d3.time.months(start, end, 1)
[Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]
> d3.time.days(start, end, 1)
[Thu Dec 30 2010 00:00:00 GMT+0000 (GMT Standard Time), Fri Dec 31 2010 00:00:00 GMT+0000 (GMT Standard Time), Sat Jan 01 2011 00:00:00 GMT+0000 (GMT Standard Time)]
the above indicates that day.range starts from the first item and ends just before the second, while month.range seems to do the opposite.
In the documentation it's stated:
# d3.time.months(start, stop[, step])
Alias for d3.time.month.range. Returns the month boundaries (e.g., January 01)
after or equal to start and before stop. If step is specified, then every step'th
month will be returned, based on the month of the year. For example, a step of 3
will return January, April, July, etc.
after or equal to start and before stop is also mentioned for time.days but the result appears to be different. Also, when these functions return after and when equal to the start? What makes the difference?
NB: my wish would be having these functions returning arrays of days, months, years including both start and end parameters.
As clearly explained in here the behaviour is in fact consistent. Both day.range and month.range aim to return each daily and monthly boundaries between the start and end parameter.