I’m working on a bigger school project, trying to classify timeseries measurements with Minirocket/Rocket. My trainingdata consists of a 1D matrix containing the measurements, and a seperate 1D matrix containing the corresponding labels (0/1). The matrices are equal length, so there is a label for each measurement value. I tried to run the program, which worked with other sample data, but I always receive the following error: “ValueError: Found input variables with inconsistent numbers of samples: [1, 321408]”. What am I doing wrong here? Do I have to format the training data differently or are there any other settings for MiniRocket which I have to adapt as well?
The error is triggered by the following line of code: classifier.fit(train_x_transform, train_y)
This is the full code that I tried running so far:
import pandas as pd
from sklearn.metrics import classification_report
from sktime.transformations.panel.rocket import MiniRocket
from sklearn.linear_model import RidgeClassifierCV
import numpy as np
# Load the data
def load_data(file_path):
data = pd.read_csv(file_path)
X = data['sensor_values_final'].values
y = data['labels'].values
assert len(X) == len(y), "Length of X and y do not match"
return X, y
train_x, train_y = load_data(r'csvTrainingData_2024-05-18_18-21-46_train.csv')
test_x, test_y = load_data(r'csvTrainingData_2024-05-18_18-21-46_test.csv')
# Transform the data
minirocket = MiniRocket(10_000) # by default, MiniRocket uses ~10,000 kernels
minirocket.fit(train_x)
train_x_transform = minirocket.transform(train_x)
test_x_transform = minirocket.transform(test_x)
# Train the model
classifier = RidgeClassifierCV(alphas=np.logspace(-3, 3, 10))
classifier.fit(train_x_transform, train_y)
# Evaluate the model
train_y_pred = classifier.predict(train_x_transform)
test_y_pred = classifier.predict(test_x_transform)
print("Test set performance:")
print(classification_report(test_y, test_y_pred))
Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.