【问题标题】:ValueError: Shape of passed values is (1027, 8), indices imply (1030, 8)ValueError:传递值的形状为 (1027, 8),索引暗示 (1030, 8)
【发布时间】:2021-10-31 19:42:04
【问题描述】:
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的形状来修复。

【问题讨论】:

    标签: python-3.x machine-learning numpy-ndarray


    【解决方案1】:

    你可以使用这些行:

    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)
    

    【讨论】:

    • @TheAfg 欢迎老兄,如果可以请upvote
    • 很遗憾,我做不到,因为我没有足够的回报。
    猜你喜欢
    • 1970-01-01
    • 2020-01-12
    • 2018-10-15
    • 2020-05-21
    • 2021-12-05
    • 2021-05-12
    • 1970-01-01
    • 2019-01-27
    • 2013-11-09
    相关资源
    最近更新 更多