TypeError Traceback (most recent call last)
Cell In[3], line 101
99 # 主函数
100 if __name__ == "__main__":
--> 101 main()
103 # 可视化结果
104 plt.figure(figsize=(14, 6))
Cell In[2], line 26, in main()
23 y_train, y_test = y[:split_index], y[split_index:]
25 # 数据归一化
---> 26 X_train_scaled, X_test_scaled, scaler = normalize_data(X_train, X_test)
28 # 构建模型
29 input_shape = (X_train_scaled.shape[1], X_train_scaled.shape[2])
Cell In[3], line 76, in normalize_data(X_train, X_test)
74 # 创建并拟合归一化器 - 仅使用数值数据
75 scaler = MinMaxScaler(feature_range=(0, 1))
---> 76 X_train_scaled = scaler.fit_transform(X_train_reshaped)
77 X_test_scaled = scaler.transform(X_test_reshaped)
79 # 恢复原始形状 (samples, timesteps, features)
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\_set_output.py:316, in _wrap_method_output.<locals>.wrapped(self, X, *args, **kwargs)
314 @wraps(f)
315 def wrapped(self, X, *args, **kwargs):
--> 316 data_to_wrap = f(self, X, *args, **kwargs)
317 if isinstance(data_to_wrap, tuple):
318 # only wrap the first output for cross decomposition
319 return_tuple = (
320 _wrap_data_with_container(method, data_to_wrap[0], X, self),
321 *data_to_wrap[1:],
322 )
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\base.py:894, in TransformerMixin.fit_transform(self, X, y, **fit_params)
879 warnings.warn(
880 (
881 f"This object ({self.__class__.__name__}) has a `transform`"
(...)
889 UserWarning,
890 )
892 if y is None:
893 # fit method of arity 1 (unsupervised transformation)
--> 894 return self.fit(X, **fit_params).transform(X)
895 else:
896 # fit method of arity 2 (supervised transformation)
897 return self.fit(X, y, **fit_params).transform(X)
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\preprocessing\_data.py:454, in MinMaxScaler.fit(self, X, y)
452 # Reset internal state before fitting
453 self._reset()
--> 454 return self.partial_fit(X, y)
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\base.py:1365, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
1358 estimator._validate_params()
1360 with config_context(
1361 skip_parameter_validation=(
1362 prefer_skip_nested_validation or global_skip_validation
1363 )
1364 ):
-> 1365 return fit_method(estimator, *args, **kwargs)
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\preprocessing\_data.py:494, in MinMaxScaler.partial_fit(self, X, y)
491 xp, _ = get_namespace(X)
493 first_pass = not hasattr(self, "n_samples_seen_")
--> 494 X = validate_data(
495 self,
496 X,
497 reset=first_pass,
498 dtype=_array_api.supported_float_dtypes(xp),
499 ensure_all_finite="allow-nan",
500 )
502 device_ = device(X)
503 feature_range = (
504 xp.asarray(feature_range[0], dtype=X.dtype, device=device_),
505 xp.asarray(feature_range[1], dtype=X.dtype, device=device_),
506 )
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:2954, in validate_data(_estimator, X, y, reset, validate_separately, skip_check_array, **check_params)
2952 out = X, y
2953 elif not no_val_X and no_val_y:
-> 2954 out = check_array(X, input_name="X", **check_params)
2955 elif no_val_X and not no_val_y:
2956 out = _check_y(y, **check_params)
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\validation.py:1053, in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_writeable, force_all_finite, ensure_all_finite, ensure_non_negative, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)
1051 array = xp.astype(array, dtype, copy=False)
1052 else:
-> 1053 array = _asarray_with_order(array, order=order, dtype=dtype, xp=xp)
1054 except ComplexWarning as complex_warning:
1055 raise ValueError(
1056 "Complex data not supported\n{}\n".format(array)
1057 ) from complex_warning
File ~\anaconda3\envs\myenv\Lib\site-packages\sklearn\utils\_array_api.py:757, in _asarray_with_order(array, dtype, order, copy, xp, device)
755 array = numpy.array(array, order=order, dtype=dtype)
756 else:
--> 757 array = numpy.asarray(array, order=order, dtype=dtype)
759 # At this point array is a NumPy ndarray. We convert it to an array
760 # container that is consistent with the input's namespace.
761 return xp.asarray(array)
TypeError: float() argument must be a string or a real number, not 'Timestamp'
最新发布