125404629 发表于 2023-10-11 16:35:05

minirocket 数据维度

光谱数据维度有855个样本,890个变量,输入minirocket出现错误。
X.shape=(855,890),Y.shape=(855,1)

发生异常: ValueError
n_timepoints must be >= 9, but found 1; zero pad shorter series so that n_timepoints == 9
File "D:\0000可见光2\程序\MiniRocket\Test1.py", line 20, in <module>
    model.fit(X_train, y_train)
ValueError: n_timepoints must be >= 9, but found 1; zero pad shorter series so that n_timepoints == 9

from tsai.all import MiniRocket
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tsai.basics import *
from tsai.models.MINIROCKET import MiniRocketClassifier

df1 = pd.read_csv("train.csv")
df1 = np.array(df1)
X = df1[:, 1:891]
X = np.expand_dims(df1[:, 1:891].astype(float), axis=2)
Y = df1[:, 0]
print(X.shape, Y.shape)
df2 = pd.read_csv("test.csv")
df2 = np.array(df1)
X_test = df2[:, 1:891]
X_train, X_valid, y_train, y_valid = train_test_split(X, Y, test_size=0.8, random_state=42)
print(X_train.shape, y_train.shape, X_valid.shape, y_valid.shape)
model = MiniRocketClassifier()
model.fit(X_train, y_train)

cls = MiniRocket()
y=model.score(X_valid, y_valid)
print(y)

isdkz 发表于 2023-10-11 16:35:24

这个错误是因为 MiniRocket 要求输入的时间序列长度至少为 9,而您的数据长度只有 1,因此需要使用零填充将其长度增加到 9。您可以使用 tsai 库中的 pad_min_len 函数来实现这一点。以下是修改后的代码:

from tsai.all import MiniRocket, pad_min_len
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tsai.basics import *
from tsai.models.MINIROCKET import MiniRocketClassifier

df1 = pd.read_csv("train.csv")
df1 = np.array(df1)
X = df1[:, 1:891]
X = np.expand_dims(df1[:, 1:891].astype(float), axis=2)
Y = df1[:, 0]
print(X.shape, Y.shape)
df2 = pd.read_csv("test.csv")
df2 = np.array(df1)
X_test = df2[:, 1:891]

# 使用 pad_min_len 函数将 X 的长度增加到 9
X = pad_min_len(X, 9)

X_train, X_valid, y_train, y_valid = train_test_split(X, Y, test_size=0.8, random_state=42)
print(X_train.shape, y_train.shape, X_valid.shape, y_valid.shape)
model = MiniRocketClassifier()
model.fit(X_train, y_train)

cls = MiniRocket()
y = model.score(X_valid, y_valid)
print(y)


希望能够帮到您!

陶远航 发表于 2023-10-11 16:35:48

您的问题似乎是关于使用MiniRocket模型处理时间序列数据时遇到的问题。MiniRocket是一个高效的时间序列分类模型,它需要输入的数据是一个二维数组,其中每一行是一个时间序列样本,每一列是一个时间点。

在您的代码中,您使用了np.expand_dims(df1[:, 1:891].astype(float), axis=2)来增加一个维度,这可能是问题的原因。这一步将数据从二维转换为三维,可能导致MiniRocket无法正确处理。

另外,错误信息n_timepoints must be >= 9, but found 1; zero pad shorter series so that n_timepoints == 9表明,MiniRocket期望每个时间序列样本至少有9个时间点,但在您的数据中只找到了1个。这可能是因为增加了一个不必要的维度导致的。

您可以尝试以下修改:

from tsai.all import MiniRocket
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tsai.basics import *
from tsai.models.MINIROCKET import MiniRocketClassifier

df1 = pd.read_csv(\"train.csv\")
df1 = np.array(df1)
X = df1[:, 1:891].astype(float)# 不增加额外的维度
Y = df1[:, 0]
print(X.shape, Y.shape)

df2 = pd.read_csv(\"test.csv\")
df2 = np.array(df1)
X_test = df2[:, 1:891]

X_train, X_valid, y_train, y_valid = train_test_split(X, Y, test_size=0.8, random_state=42)
print(X_train.shape, y_train.shape, X_valid.shape, y_valid.shape)

model = MiniRocketClassifier()
model.fit(X_train, y_train)

cls = MiniRocket()
y=model.score(X_valid, y_valid)
print(y)


这样,您的数据应该能够正确地被MiniRocket模型处理。
请注意,本回答来自GPT-4
如果问题已经解决,请设置最佳答案
页: [1]
查看完整版本: minirocket 数据维度