I'm working on my first pipeline but I can't get it to work on the Titanic dataset. Can someone please explain what I'm doing wrong and how I can fix it?
I dropped some features from the dataframe and used get dummies to transform categorical features.
titanic_dummies = titanic.copy()
titanic_dummies = titanic_dummies.drop([ 'Name', 'Ticket','Cabin', "Fare"], axis=1)
titanic_dummies = pd.get_dummies(titanic_dummies, drop_first=True)
Then I tried to run this pipeline
X=titanic_dummies.drop(['Survived'], axis=1)
y=titanic_dummies['Survived']
****#setup the pipeline steps****
steps = [('scaler', StandardScaler()),
('imputation', SimpleImputer(missing_values='NaN', strategy='most_frequent')),
('logreg', LogisticRegression())]
*# Create the pipeline: pipeline*
pipeline = Pipeline(steps)
#Define hyperparameters and range of Grid Search
parameters = {"logreg__C": np.logspace(-5, 8, 15),
"logreg__penalty": ['l1', 'l2']}
*# Create train and test sets*
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
*# run cross validation*
cv = GridSearchCV(pipeline, param_grid = parameters, cv=3)
*# Fit the pipeline to the training set:*
cv.fit(X_train, y_train)
*# Predict the labels of the test set*
y_pred = cv.predict(X_test)
*# Compute and print metrics*
print("Accuracy: {}".format(cv.score(X_test, y_test)))
print(classification_report(y_test, y_pred))
print("Tuned Model Parameters: {}".format(cv.best_params_))
This is the error that I get
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
From the attached picture you can probably tell that the size of my values are not the issue. Perhaps something goes wrong with my imputation?
I really love to hear your thoughts on how I can fix this.
