python - 创建预测时的索引问题
问题描述
需要帮助,我对熊猫和 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"
解决方案
推荐阅读
- java - 没有注释的 ArangoDB Java 驱动程序边缘
- spring - 带有 Vaadin 的 Spring Boot - 使用外键
- angularjs - 如何验证是否在AngularJs中使用jqLite检查了一个复选框
- linux - 使用来自文本和空行的数据创建 .csv
- python - 使用自定义字段扩展 Django 模型并保存逻辑
- bash - 覆盖现有 shell 命令的最佳方法是什么?
- javascript - 访问控制允许来源的 JAVASCRIPT XMLHttpRequest() 问题
- c++ - 创建文件/home/m/OpenCV/modules/core/src/matrix_wrap.cpp,第 1461 行中的空指针(为缺少的输出数组调用 create())
- python - 如何从另一个字符串中删除一个强字符
- oracle11g - 使用 unpivot 从远程表插入