Skip to content
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

Linear Regression with time series data? #719

Open
hbcondo opened this issue Apr 14, 2024 · 2 comments
Open

Linear Regression with time series data? #719

hbcondo opened this issue Apr 14, 2024 · 2 comments

Comments

@hbcondo
Copy link

hbcondo commented Apr 14, 2024

Hi, are there any recommendations on how to use the linearRegression method for finding the slope of a regression line for time series data? For example, the x-coordinate value would be a JavaScript Date object so how would you pass that in when the data parameters just accept an array of numbers? Any insights on this is appreciated.

@tmcw
Copy link
Member

tmcw commented Apr 15, 2024

Dates in JavaScript can be cast to number by using the + operator or using .getTime(). I'd recommend casting your dates to strings, running the linear regression algorithm, and then you can cast back to dates using the date constructor with the numbers.

@hbcondo
Copy link
Author

hbcondo commented Apr 15, 2024

Thank you for this prompt reply; much appreciated. I passed-in the number of milliseconds returned by .getTime() into the linearRegression method but since its value is so large, the slope value retuned is too small and is expressed in scientific notation (ex. -9.483616519037679e-8). To adjust for this, I converted milliseconds to days which returned readable numbers (ex. -8.14423076923077)

I'm still reviewing how this works but wanted to report back and see if there is by chance any further guidance on using time series data with this library's linear regression function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants