我的预测结果如下:

Predictions= [[0.39963388 0.44170195 0.37929803 0.1575233  0.24030758]]


我的标签如下:

Columns: ['desert', 'mountains', 'sea', 'sunset', 'trees']


如何使这两个值,即PredictionsColumns成为一个数据帧?

如:

      Labels  Columns
0     desert  0.39963388
1  mountains  0.44170195
2        sea  0.37929803
3     sunset  0.1575233
4      trees  0.24030758

最佳答案

您可以尝试以下方法:

import pandas as pd
Predictions= [[0.39963388, 0.44170195, 0.37929803, 0.1575233, 0.24030758]]
df = pd.DataFrame(Predictions, columns= ['desert', 'mountains', 'sea', 'sunset', 'trees']).T.reset_index()
df.columns = ['Labels', 'Predictions']
print(df)


      Labels  Predictions
0     desert     0.399634
1  mountains     0.441702
2        sea     0.379298
3     sunset     0.157523
4      trees     0.240308

关于python - 如何在Panda DataFrame中拟合预测值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59470107/

10-12 17:47