【发布时间】:2018-09-11 09:57:33
【问题描述】:
我已经对数据集进行了预处理,并检查了自变量可能存在的多重共线性。
数据集有 6 列 31 行,我用来生成 1/3 作为 X_test 和 y_test,剩下的是 X_train 和 y_train。
我使用 sklearn.linear_model LinearRegression 函数将 X_train 和 y_train 拟合到回归量,并使用 X_test 的 predict 函数得到 y 的预测值。
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('daily_raw_status.csv')
X = dataset.iloc[:, :-1].values # IVs
y = dataset.iloc[:, 6].values # DV
# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3, random_state = 0)
# Fitting MLR to the Training Set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression() # create object
regressor.fit(X_train, y_train) # using fit method, fit the multiple regressor to training set
# Predicting the Test set results
y_pred = regressor.predict(X_test)
Now that I have the y_pred, I can now check the y_pred to the y_test if it's nearly the same.
问题是:
我还能用 y_pred 做什么,或者在解释模型时我应该把重点放在哪里?以及关于如何将模型重新用于可能的实时数据集的任何想法/概念?
【问题讨论】:
标签: machine-learning regression linear-regression