ValueError: 传递的值的形状为(1027, 8),索引暗示(1030, 8)

import numpy as npimport pandas as pddf = pd.read_csv('concrete_data.csv', delimiter=',', sep=r', ')X_raw = df.drop(['concrete_compressive_strength'], axis=1)y_raw =  df['concrete_compressive_strength']# 隔离标记数据集的示例n_labeled_examples = X_raw.shape[0]training_indices = np.random.randint(low=0, high=len(X_raw)+1, size=3)# 定义训练数据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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注