0
$\begingroup$

I have built the model on Titanic Data set , with Logistic Regression Succeffullly and it is giving prediction on training set , but unfortunately I am unable to implement this on test data set.

Following code for reference :

training = training[['PassengerId','Sex','Embarked','Pclass','Age','SibSp','Survived']] # 0.78 
X = training.iloc[:, :-1]
y = training.iloc[:, -1]

from sklearn.compose import make_column_transformer
from sklearn.preprocessing import OneHotEncoder
ct = make_column_transformer((OneHotEncoder(), ['Sex', 'Embarked']), remainder = 'passthrough')
X = ct.fit_transform(X)

from sklearn.preprocessing import StandardScaler
sc =StandardScaler()
X=sc.fit_transform(X)

from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression(solver = 'lbfgs')

from sklearn.model_selection import cross_val_score

cross_val_score(logreg, X,y, cv=5, scoring ='accuracy').mean()

As in the test data set , I don't have y data that means the predictive column so I introduced it with the help of null values.

But unable to take it forward, Can you please guide , how I can run Logistic Regression Model on test data set of Titanic.

Thanks a lot .

$\endgroup$
0
$\begingroup$

Why don't you use the predict function from the LogisticRegression model trained with the training data?

For example:

y_pred = logreg.predict(X_test)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.