我有一个看起来像这样的Numpy数组:
[400.31865662]
[401.18514808]
[404.84015554]
[405.14682194]
[405.67735105]
[273.90969447]
[274.0894528]
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码将其转换为Panda Dataframe时
y = pd.DataFrame(data)
print(y)
Run Code Online (Sandbox Code Playgroud)
打印时得到以下输出。为什么我得到所有这些zéros?
0
0 400.318657
0
0 401.185148
0
0 404.840156
0
0 405.146822
0
0 405.677351
0
0 273.909694
0
0 274.089453
Run Code Online (Sandbox Code Playgroud)
我想要一个看起来像这样的单列数据框:
400.31865662
401.18514808
404.84015554
405.14682194
405.67735105
273.90969447
274.0894528
Run Code Online (Sandbox Code Playgroud) 你可以在下面找到我在互联网上找到的代码来构建一个简单的神经网络。Everyhting 工作正常,但当我对 y 标签进行编码时,我得到的预测给出了这个结果:
2 0 1 2 1 2 2 0 2 1 0 0 0 1 1 1 1 1 1 1 2 1 2 1 0 1 0 1 0 2
所以现在我需要将它转换回原来的花类(Iris-virginica 等)。我需要使用 inverse_transform 方法,但你能帮忙吗?
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import classification_report, confusion_matrix
# Location of dataset
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
# Assign colum names to the dataset
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'Class'] …Run Code Online (Sandbox Code Playgroud)