AttributeError: ‘Series‘ object has no attribute ‘as_matrix‘

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AttributeError: ‘Series‘ object has no attribute ‘as_matrix‘相关的知识,希望对你有一定的参考价值。

AttributeError: 'Series' object has no attribute 'as_matrix'

问题:

y_test = test_shifted["y_t+1"].as_matrix()
X_test = test_shifted[["load_t-" + str(T - t) for t in range(1, T + 1)]].as_matrix()

look_back_dt = dt.datetime.strptime(test_st_data_load, "%Y-%m-%d %H:%M:%S") - dt.timedelta(
    hours=T - 1
)
test = ts_data_load.copy()[test_st_data_load:][["load"]]

test["load"] = scaler.transform(test)

test_shifted = test.copy()
test_shifted["y_t+1"] = test_shifted["load"].shift(-1, freq="H")
for t in range(1, T + 1):
    test_shifted["load_t-" + str(T - t)] = test_shifted["load"].shift(T - t, freq="H")

test_shifted = test_shifted.dropna(how="any")

y_test = test_shifted["y_t+1"].as_matrix()
X_test = test_shifted[["load_t-" + str(T - t) for t in range(1, T + 1)]].as_matrix()
X_test = X_test.reshape(X_test.shape[0], T, 1)

解决:

y_test = test_shifted["y_t+1"].values
X_test = test_shifted[["load_t-" + str(T - t) for t in range(1, T + 1)]].values

look_back_dt = dt.datetime.strptime(test_st_data_load, "%Y-%m-%d %H:%M:%S") - dt.timedelta(
    hours=T - 1
)
test = ts_data_load.copy()[test_st_data_load:][["load"]]

test["load"] = scaler.transform(test)

test_shifted = test.copy()
test_shifted["y_t+1"] = test_shifted["load"].shift(-1, freq="H")
for t in range(1, T + 1):
    test_shifted["load_t-" + str(T - t)] = test_shifted["load"].shift(T - t, freq="H")

test_shifted = test_shifted.dropna(how="any")

y_test = test_shifted["y_t+1"].values
X_test = test_shifted[["load_t-" + str(T - t) for t in range(1, T + 1)]].values
X_test = X_test.reshape(X_test.shape[0], T, 1)

完整错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-56-684a288a14c0> in <module>
     13 test_shifted = test_shifted.dropna(how="any")
     14 
---> 15 y_test = test_shifted["y_t+1"].as_matrix()
     16 X_test = test_shifted[["load_t-" + str(T - t) for t in range(1, T + 1)]].as_matrix()
     17 X_test = X_test.reshape(X_test.shape[0], T, 1)

D:\\anaconda\\lib\\site-packages\\pandas\\core\\generic.py in __getattr__(self, name)
   5463             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5464                 return self[name]
-> 5465             return object.__getattribute__(self, name)
   5466 
   5467     def __setattr__(self, name: str, value) -> None:

AttributeError: 'Series' object has no attribute 'as_matrix'

df.as_matrix() was deprecated after version 0.23.0. Use df.values instead.

Follow this link for additional information.

参考:'DataFrame' object has no attribute 'as_matrix 

以上是关于AttributeError: ‘Series‘ object has no attribute ‘as_matrix‘的主要内容,如果未能解决你的问题,请参考以下文章

AttributeError:“系列”对象没有属性“行”

如何从pandas Series类继承以简化Series类型的子集?

AttributeError:“系列”对象没有属性“to_coo”

pandas Series' 对象没有属性 'find'

AttributeError: ‘DatetimeProperties’ object has no attribute ‘weekday_name’ 的解决方法

AttributeError: ‘DatetimeProperties’ object has no attribute ‘weekday_name’ 的解决方法