创建预测时的索引问题

时间:2018-05-06 18:45:20

标签: python

需要帮助,我对熊猫和sci工具包很新。我使用以下代码获得索引错误。请告诉我如何在此处提到的列中添加索引。错误来自预测区域

# 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"

0 个答案:

没有答案