简体   繁体   中英

ValueError: If using all scalar values, you must pass an index in python

I got a value error when i use ramdom forest to do the prediction. i have attached the code and error message below

thank you

在此处输入图像描述

在此处输入图像描述

Hello!

First of all reason why this problem occurs is as Pandas is expecting the data values to be list values or dict values. I don't know what is your values exactly however, you can give the dataframe object index parameter to get rid of this simple problem.

Firstly create a list of arbitrary numbers

numbers = pd.Index(range(max(y_test, y_pred))

than add this line to use these indexes.

df = df.set_index(numbers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM