The problem is in using datetime64[ns]
type on x-axis.
(问题是在x轴上使用datetime64[ns]
类型。)
There is an issue on github about how datetime64[ns]
is handled inside sklearn
. (github上有一个问题,关于如何在sklearn
处理datetime64[ns]
。)
The thing is datetime64[ns]
features are scaled as features of the order of 101? in this case: (在这种情况下, datetime64[ns]
功能按比例缩放为101?左右。)
x_poly
Out[91]:
array([[1.00000000e+00, 1.29911040e+18, 1.68768783e+36, 2.19249281e+54],
[1.00000000e+00, 1.33617600e+18, 1.78536630e+36, 2.38556361e+54],
[1.00000000e+00, 1.39129920e+18, 1.93571346e+36, 2.69315659e+54],
[1.00000000e+00, 1.41566400e+18, 2.00410456e+36, 2.83713868e+54],
[1.00000000e+00, 1.43354880e+18, 2.05506216e+36, 2.94603190e+54],
[1.00000000e+00, 1.47061440e+18, 2.16270671e+36, 3.18050764e+54],
[1.00000000e+00, 1.49670720e+18, 2.24013244e+36, 3.35282236e+54],
[1.00000000e+00, 1.51476480e+18, 2.29451240e+36, 3.47564662e+54],
[1.00000000e+00, 1.57610880e+18, 2.48411895e+36, 3.91524174e+54]])
The easiest way to handle it is to use StandardScaler
or convert datetime using pd.to_numeric
and scale it:
(处理它的最简单方法是使用StandardScaler
或使用pd.to_numeric
转换datetime并pd.to_numeric
进行缩放:)
scaler = StandardScaler()
x_scaled = scaler.fit_transform(np.c_[data['Date']])
or simply
(或简单地)
x_scaled = np.c_[pd.to_numeric(data['Date'])] / 10e17 # convert and scale
That gives appropriately scaled features:
(这给出了适当缩放的功能:)
x_poly = polynomial_features.fit_transform(x_scaled)
x_poly
Out[94]:
array([[1. , 1.2991104 , 1.68768783, 2.19249281],
[1. , 1.336176 , 1.7853663 , 2.38556361],
[1. , 1.3912992 , 1.93571346, 2.69315659],
[1. , 1.415664 , 2.00410456, 2.83713868],
[1. , 1.4335488 , 2.05506216, 2.9460319 ],
[1. , 1.4706144 , 2.16270671, 3.18050764],
[1. , 1.4967072 , 2.24013244, 3.35282236],
[1. , 1.5147648 , 2.2945124 , 3.47564662],
[1. , 1.5761088 , 2.48411895, 3.91524174]])
The result will be looking like this afterwards:
(之后的结果将如下所示:)