【问题标题】:Unable to understand a part of code about Linear Regression from sentdex tutorials on machine learning无法理解机器学习 sentdex 教程中有关线性回归的部分代码
【发布时间】:2021-04-07 16:46:20
【问题描述】:

在 youtube 上关注 Sentdex 机器学习教程。在第 5 部分中,他这样做了

forecast_out = int(math.ceil(0.01*len(df)))
print(forecast_out)

df['label'] = df[forecast_col].shift(-forecast_out)

X = np.array(df.drop(['label'],1))
X = preprocessing.scale(X)
X = X[:-forecast_out]
X_lately = X[-forecast_out:]


df.dropna(inplace=True)
y = np.array(df['label'])
y = np.array(df['label'])

我完全迷失了他在这里想要做什么。在int(math.ceil(0.01*len(df))) 中,他试图获得他想要找到预测的天数。在那之后,他做了df[forecast_col].shift(-forecast_out),然后我什么也做不了。

【问题讨论】:

  • 阅读shift 的文档应该会有所帮助。
  • 但是`(-forecast_out)`在做什么

标签: python pandas numpy machine-learning linear-regression


【解决方案1】:

这里没有足够的信息,但是如果这是一个时间序列预测问题,那么我认为df[forecast_col].shift(-forecast_out)将预测列向上移动'forecast_out'天数,以便特定日期的标签列将是您需要预测的数字(即从未来转移的数字)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 2019-04-17
    • 2020-03-27
    • 1970-01-01
    • 2019-08-12
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多