ValueError: Shape of passed values is (1027, 8), indices imply (1030, 8)

ValueError: Shape of passed values is (1027, 8), indices imply (1030, 8)

import numpy as np
import pandas as pd

df = pd.read_csv('concrete_data.csv', delimiter=',', sep=r', ')
X_raw = df.drop(['concrete_compressive_strength'], axis=1)
y_raw =  df['concrete_compressive_strength']

# Isolate our examples for our labeled dataset.
n_labeled_examples = X_raw.shape[0]
training_indices = np.random.randint(low=0, high=len(X_raw)+1, size=3)

# Defining the training data
X_training = X_raw.iloc[training_indices]
y_training = y_raw.iloc[training_indices]

这些变量的形状是:

X_training.shape

(3, 8)

y_training.shape

(3,)

X_raw.shape

(1030, 8)

y_raw.shape

(1030,)

现在,我想隔离非训练示例:

X_pool = np.delete(X_raw, training_indices, axis=0)
y_pool = np.delete(y_raw, training_indices, axis=0)

这给了我以下错误?

ValueError: Shape of passed values is (1027, 8), indices imply (1030, 8)

我尝试重塑 training_indices 但仍然出现相同的错误。

r = np.reshape(training_indices, (3,1), order='C')

请问是哪里出了问题,如何修改training_indices的形状才能修复

您可以使用这些行:

X_pool = X_raw.drop(training_indices.tolist())
y_pool = y_raw.drop(training_indices.tolist())

而不是这些行:

X_pool = np.delete(X_raw, training_indices, axis=0)
y_pool = np.delete(y_raw, training_indices, axis=0)