【发布时间】:2019-10-15 05:12:51
【问题描述】:
我正在尝试使用简单的线性回归来预测某个项目的成本。作为输入数据,我使用项目的成本。
代码似乎可以工作,但我无法理解在应用线性回归时如何使用 X 和 Y。我使用 X 作为项目成本,使用 Y 作为标签(使用 X 的移位数据创建一个新行)
df = df[['Item Price']]
forecast_col = 'Item Price'
forecast_out = int(math.ceil(0.0000005 * len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)
X = df[['Item Price']]
X = preprocessing.scale(X)
X_lately = X[forecast_out:]
X = X[:-forecast_out]
df.dropna(inplace=True)
y = np.array(df['label'])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
clf = LinearRegression(n_jobs=-1)
clf.fit(X_train, y_train)
forecast_set = clf.predict(X)
在求解 Y = a + bX 的线性回归方程时 X 和 Y 变量如何使用
【问题讨论】:
标签: python pandas machine-learning linear-regression