/usr/local/lib/python3.10/dist-packages/ipykernel/ipkernel.py:283: DeprecationWarning: should_run_async
will not call transform_cell
automatically in the future. Please pass the result to transformed_cell
argument and any exception that happen during thetransform in preprocessing_exc_tuple
in IPython 7.17 and above.
and should_run_async(code)
歷史數據分析結果:
num_1 num_2 num_3 num_4 num_5
count 1895.000000 1895.000000 1895.000000 1895.000000 1895.000000
mean 6.302375 12.295515 18.646966 24.896042 31.127704
std 5.216928 6.459218 7.393696 7.584878 7.464562
min 1.000000 2.000000 3.000000 4.000000 7.000000
25% 2.000000 7.000000 13.000000 20.000000 26.000000
50% 5.000000 12.000000 18.000000 25.000000 32.000000
75% 9.000000 16.000000 24.000000 30.500000 37.000000
max 33.000000 36.000000 41.000000 44.000000 47.000000
num_6 num_7
dateutil
. To ensure parsing is consistent and as-expected, please specify a format.
_index = to_datetime(index)
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:473: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
self._init_dates(dates, freq)
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:559: UserWarning: Could not infer format, so each element will be parsed individually, falling back to dateutil
. To ensure parsing is consistent and as-expected, please specify a format.
_index = to_datetime(index)
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:473: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
self._init_dates(dates, freq)
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:559: UserWarning: Could not infer format, so each element will be parsed individually, falling back to dateutil
. To ensure parsing is consistent and as-expected, please specify a format.
_index = to_datetime(index)
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:473: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
self._init_dates(dates, freq)
時間序列分析預測結果:
Empty DataFrame
Columns: [forecast]
Index: []
/usr/local/lib/python3.10/dist-packages/statsmodels/base/model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
warnings.warn("Maximum Likelihood optimization failed to "
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:836: ValueWarning: No supported index is available. Prediction results will be given with an integer index beginning at start
.
return get_prediction_index(
/usr/local/lib/python3.10/dist-packages/statsmodels/tsa/base/tsa_model.py:836: FutureWarning: No supported index is available. In the next version, calling this method in a model without a supported index will result in an exception.
return get_prediction_index(ValueError Traceback (most recent call last) <ipython-input-6-07659a6981b1> in <cell line: 2091>() 2089 # 步驟 3: 聚類分析 2090 # 將預測結果添加到 DataFrame -> 2091 forecast_df['cluster'] = KMeans(n_clusters=7, random_state=42).fit_predict(forecast_df) 2092 2093 # 聚類分析結果
4 frames /usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name) 965 n_samples = _num_samples(array) 966 if n_samples < ensure_min_samples: --> 967 raise ValueError( 968 "Found array with %d sample(s) (shape=%s) while a" 969 " minimum of %d is required%s."
ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required by KMeans.
從您提供的錯誤信息來看,您在進行時間序列分析和聚類分析時遇到了一些問題。以下是一些可能的原因和解決方案:
時間序列預測結果為空:
KMeans 聚類分析的數據問題:
forecast_df
是空的。forecast_df
是否包含有效的預測數據。如果預測結果為空,則無法進行聚類分析。數據格式問題:
UserWarning
和 ValueWarning
表示在處理日期時間索引時出現了問題。確保您的時間序列數據具有正確的日期時間格式,並且在進行分析之前已經正確設置索引。檢查數據:
調整模型參數:
添加錯誤處理:
forecast_df
是否為空。如果是空的,則跳過聚類分析或提供適當的錯誤信息。示例代碼:
# 檢查預測結果是否為空
if not forecast_df.empty:
forecast_df['cluster'] = KMeans(n_clusters=7, random_state=42).fit_predict(forecast_df)
else:
print("預測結果為空,無法進行聚類分析。")
通過這些步驟,您應該能夠找到問題的根源並進行相應的修正。