如何通过测试数据集预测y值?

时间:2018-10-29 23:17:07

标签: python data-science logistic-regression predict test-data

我已经使用下面的训练数据集成功建立了逻辑回归模型。

X = train.drop('y', axis=1)
y = train['y']

X_train, X_test, y_train, y_test = train_test_split(X, y, 
                                                    test_size=0.5)

scaler = StandardScaler()  
scaler.fit(X_train)

X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

logreg1 = LogisticRegression()
logreg1.fit(X_train, y_train)

score = logreg1.score(X_test, y_test)
cvs = cross_val_score(logreg1, X_test, y_test, cv=5).mean()

我的问题是我想引入测试数据集来预测未知的y值。在测试数据中没有y列。如何使用单独的测试数据集预测y值?

1 个答案:

答案 0 :(得分:0)

使用predict():

y_pred = logreg1.predict(X_test)
score = logreg1.score(X_test, y_pred)
print(y_pred)     // see the predictions