我想将我的数据分成标签,因为前6列决定了第7列,现在我已经选择了前6列,它工作得很好
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import classification_report, confusion_matrix
#Assign column names to the dataset
names=['buying', 'maint', 'doors', 'persons', 'lug_boot','safety', 'class']
# load the dataset in csv format into the pandas dataframe
cardata= pd.read_csv(r'C:\Users\user\Downloads\car.data', names=names)
X = cardata.iloc[:, 0:6]上面的代码运行得很好,当我运行
print(X.head())

它打印前6列,但不打印应该预测的最后一列。但下面的代码似乎不起作用,因为它输出的行为与上面的类似
y = cardata.select_dtypes(include=[object])
print(y.head())请帮助我,我只需要将变量y赋值给最后一列,即第七列
输出是相同的,但情况并非如此,当我运行print(y.head())时,它只打印最后一列
发布于 2021-04-12 23:37:35
尝尝这个
X,y = cardata.iloc[:,:-1],cardata.iloc[:,-1]这将选择所有行,并根据最后一列( X = -1)分隔索引和y。这应该会得到您想要的结果
https://stackoverflow.com/questions/67058606
复制相似问题