Message Boards Message Boards

0
|
2081 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How Predict with date and lists?

Posted 1 year ago

Hello, I want to predict with dates, so I make a function of dates with lists, but I found I can't use lists after ->. How to resolve this problem? Thanks.

a = {DateObject[{2021, 01, 01}] -> {1, 2}, 
DateObject[{2021, 01, 02}] -> {3, 4}};
b=Predict[a];c=b[DateObject[{2021, 01, 03}]]
POSTED BY: Zhenyu Zeng
2 Replies
Posted 1 year ago

One way is to encode the list to a single value. The best way to do that depends on what the elements in the list mean. A simple way that may not make sense for your data is to treat each element as a digit in an integer. E.g.

a = {DateObject[{2021, 01, 01}] -> {1, 2}, DateObject[{2021, 01, 02}] -> {3, 4}};
encoded = a /. HoldPattern[d_DateObject -> l_List] :> d -> FromDigits@l

p = Predict[encoded]
p[DateObject[{2021, 01, 01}]] // Round // IntegerDigits
(* {1, 2} *)

Another option is to create a separate predictor function for each element. E.g.

data = Map[Thread, a] // Transpose
pf = Predict /@ data
pFun[x_] := #[x] & /@ pf

pFun[DateObject[{2021, 1, 1}, "Day"]]
(* {1., 2.} *)

Another option would be to use a neural net, giving you the flexibility to customize the model to suit your data.

You know the problem domain and the nature of the data, so you can decide which approach is the best.

POSTED BY: Updating Name
Posted 1 year ago

Thanks. It's a bit esoteric, I'll ponder.

POSTED BY: Zhenyu Zeng
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract