很抱歉我有一个关于Python的问题(这是我的第一个Python脚本)。我不明白根本原因
在我的代码下面:# On découpe notre dataset en train et en test
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)
# On calcule les coefficients
est = sm.OLS(Y_train, X_train).fit()
# Export les coef dans des variables
coefSurface = est.params["surface"]
coefArrondissement = est.params["arrondissement"]
indices = [i for i, x in enumerate(X_train["surface"]) if x != "whatever"]
indices2 = [i for i, x in enumerate(X_train["arrondissement"]) if x != "whatever"]
print(indices)
print(indices2)
#TRAINING
predicted_prices = []
for n in range(0, len(Y_train)):
print((coefSurface * X_train["surface"][n]) + (coefArrondissement * X_train["arrondissement"][n]))
此代码显示:
^{pr2}$
我的两个第一次打印显示我在两个列表(0到656)上的所有可用索引。
但是当我执行一个'for'函数来计算数组的每个值时,Python崩溃了(不总是在同一个索引中),因为他似乎无法检索列表'KeyError:6'上的索引
如果你需要完整的代码我就给你
非常感谢你的帮助