简体   繁体   English

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

[英]How to predict y value with test data set?

I have successfully built logistic regression model using train dataset below. 我已经使用下面的训练数据集成功构建了逻辑回归模型。

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()

My problem is I want to bring in the test dataset to predict the unknown y value. 我的问题是我想引入测试数据集来预测未知的y值。 In the test data theres no y column. 在测试数据中没有y列。 How can I predict the y value using the seperate test dataset?? 如何使用单独的测试数据集预测y值?

Use predict(): 使用predict():

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM