【发布时间】:2020-09-13 23:31:49
【问题描述】:
我有以下代码,它试图根据非价格特征评估股票。
price = df.loc[:,'regularMarketPrice']
features = df.loc[:,feature_list]
#
X_train, X_test, y_train, y_test = train_test_split(features, price, test_size = 0.15, random_state = 1)
if len(X_train.shape) < 2:
X_train = np.array(X_train).reshape(-1,1)
X_test = np.array(X_test).reshape(-1,1)
#
model = LinearRegression()
model.fit(X_train,y_train)
#
print('Train Score:', model.score(X_train,y_train))
print('Test Score:', model.score(X_test,y_test))
#
y_predicted = model.predict(X_test)
在我的df(非常大)中,从来没有'regularMarketPrice'小于0的实例。但是,对于y_predicted中的某些点,我偶尔会收到小于0的值。
Scikit 中有没有办法说任何小于 0 的东西都是无效的预测?我希望这能让我的模型更准确。
如果需要进一步解释,请发表评论。
【问题讨论】:
标签: python pandas machine-learning scikit-learn linear-regression