sklearn.linear_model.LinearRegression with timedelta64 doesn't work

42 Views Asked by At

I have a log with some internal counter and time. Here is example:

    parrots  id                    MSK
0     16745   0 0 days 14:43:50.570000
1     95782   1 0 days 14:43:50.670000
2    180885   2 0 days 14:43:50.770000
3    255244   3 0 days 14:43:50.870000
4    335638   4 0 days 14:43:50.970000
6    498680   6 0 days 14:43:51.070000
7    575399   7 0 days 14:43:51.170000
8    655763   8 0 days 14:43:51.270000
9    735779   9 0 days 14:43:51.370000
11   895504  11 0 days 14:43:51.470000
12   975212  12 0 days 14:43:51.570000
13  1055381  13 0 days 14:43:51.670000
14  1135338  14 0 days 14:43:51.770000
16  1295328  16 0 days 14:43:51.870000
17  1377079  17 0 days 14:43:51.970000
18  1456391  18 0 days 14:43:52.070000
19  1536884  19 0 days 14:43:52.170000
21  1698646  21 0 days 14:43:52.270000
22  1776530  22 0 days 14:43:52.370000
23  1856670  23 0 days 14:43:52.470000
24  1937150  24 0 days 14:43:52.570000
26  2097155  26 0 days 14:43:52.670000
27  2176568  27 0 days 14:43:52.770000
28  2256633  28 0 days 14:43:52.870000
29  2337062  29 0 days 14:43:52.970000

where 'parrots' is counter and 'MSK' time.

dtype:
parrots              int64
id                   int64
MSK        timedelta64[ns]
dtype: object

Next, I use sklearn.linear_model.LinearRegression:

Xsubst = f01_subst_nodup[['MSK']]
ysubst = f01_subst_nodup['parrots']

msk2parrots_subst = skl.LinearRegression()
msk2parrots_subst.fit(Xsubst, ysubst)

output: LinearRegression()

Next, I check result:

ysubst_pred = msk2parrots_subst.predict(Xsubst)

Error output:
TypeError: The DType <class 'numpy.dtype[timedelta64]'> could not be promoted by <class 'numpy.dtype[float64]'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtype[timedelta64]'>, <class 'numpy.dtype[float64]'>)

What I do wrong?

Try some examples from Stackoverflow and skikit, but nothing help

0

There are 0 best solutions below