text_plain_output_1.png
from sklearn.compose import ColumnTransformer

from sklearn.impute import SimpleImputer

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import classification_report

from sklearn.model_selection import train_test_split

from sklearn.pipeline import Pipeline

from sklearn.preprocessing import OneHotEncoder, StandardScaler

import pandas as pd

import seaborn as sns

import pandas as pd
df = pd.read_csv('../input/spaceship-titanic/train.csv')
test_df = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')

useless_cols = ['PassengerId', 'Name', 'Cabin']
df.drop(columns=useless_cols, inplace=True)

import seaborn as sns
corr_matrix = df.corr()

from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.linear_model import LogisticRegression
X = df.drop(columns=['Transported'])
y = df.Transported
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
numerical_cols = [cname for cname in X.columns if X[cname].dtype in ['int64', 'float64']]
numerical_transformer = Pipeline(steps=[('imputer', SimpleImputer()), ('scaler', StandardScaler())])
categorical_cols = [cname for cname in X.columns if X[cname].nunique() < 10 and X[cname].dtype == 'object']
categorical_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='most_frequent')), ('onehot', OneHotEncoder(handle_unknown='ignore'))])
preprocessor = ColumnTransformer(transformers=[('num', numerical_transformer, numerical_cols), ('cat', categorical_transformer, categorical_cols)])
pipe = Pipeline(steps=[('preprocessor', preprocessor), ('model', LogisticRegression())])
pipe.fit(X_train, y_train)
y_pred = pipe.predict(X_test)

from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))