【发布时间】:2017-10-12 06:55:44
【问题描述】:
#I have imported the dataset with pandas
df = pd.read_csv(filename)
####Preparing data for sklearn
#1)Dropped the names of each sample
df.drop(['id'], 1, inplace=True)
#2)Isolate data and remove column with classification (X) and isolation classification column (y)
X = np.array(df.drop(['class'],1))
y = np.array(df['class'])
######
#Split data into testing/training datasets
X_train, X_test, y_train, y_test = model_selection.train_test_split(X,y,test_size=0.4)
问题:如果我想要测试/训练数据中的样本名称(测试后),我该如何检索它们?
【问题讨论】:
-
由于
train_test_split的输出是np.arrays,如果将此列表也转换为np.array,则可以将它们用作包含名称的列上的索引。 -
嗨,由于您删除了包含名称的 id 列,因此您需要再次重新加载 csv 并使用测试/训练数据集来检索 id
-
显然我可以在删除名称之前执行此操作。 IndexError:用作索引的数组必须是整数(或布尔)类型
标签: python pandas scipy scikit-learn