首页 > 解决方案 > 创建预测时的索引问题

问题描述

需要帮助,我对熊猫和 sci kit 很陌生。我收到以下代码的索引错误。请让我知道如何将索引添加到此处提到的列。错误来自预测区域

# get the dependent variable
Y_COLS = ["Trip_distance"]

# Independent variable columns
X_COLS = ["precipitation"]

# Number of trees
TREES = 15

# Set dependent variable
y = df_out[Y_COLS].values


# Set independent variable
X = df_out[X_COLS].values

make an array variable for y

y1 = y.ravel()
y= np.array(y1).astype(int)



# Prepare and train random forest model
clf = RandomForestClassifier(n_estimators=TREES)
clf.fit(X, y)

# Make prediction. This is needed for the chi-square test.
df = dataJun[(dataJun.U_manhattan==1)]
y = df[Y_COLS].values
X = df[X_COLS].values
y_pred = clf.predict(X)
y2 = y - y_pred

Error :     
Traceback (most recent call last):
  File "C:/Users/Sajith/PycharmProjects/NYCTaxi/Test.py", line 88, in <module>
    X = df[X_COLS].values
raise KeyError('%s not in index' % objarr[mask])
KeyError: "['precipitation'] not in index"

标签: python

解决方案


推荐阅读