0
$\begingroup$

I'm trying to tune my MLPClassifier using GridSearchCV, but it takes ages, so I was wondering if using PCA data will decrease its run time.

I have tried reducing my 145 features to 21 components via PCA, but it seems that because of this my MLPClassifier can no longer return probabilities using the predict_proba function. Instead, it returns the predicted target (1s and 0s, because I'm classifying a binary response). Do the PCA values affect how the MLP classifies?

For reference, please see below my code for PCA

# ==== PCA ==== #
pca = PCA()
pca.fit(X_train_std)
# Get optimum number of components
var = pca.explained_variance_
varcumsum = np.cumsum(var)
pc_impt_indx = varcumsum[np.where(varcumsum < 91)]
best_ncomp = len(pc_impt_indx)
print('PC1 to PC{} explains approximately 90% of the variance in the dataset.'.format(len(pc_impt_indx)))
# re-fit PCA
pca_opt = PCA(n_components = best_ncomp + 1)
X_train_pca = pca_opt.fit_transform(X_train)
X_test_pca = pca_opt.transform(X_test)

# ==== MLP ==== #
mlp = MLPClassifier()
# Train model
mlp.fit(X_train_pca, y_train)
# Predict
pred_test = mlp.predict(X_test_pca)
pred_test_proba = mlp.predict_proba(X_test_pca)

pred_test_proba returns:

[[0. 1.]
 [0. 1.]
 [0. 1.]
 ...
 [0. 1.]
 [0. 1.]
 [0. 1.]]

without the PCA, using the same code for MLP, I get this for pred_test_proba:

[[0.82575876 0.17424124]
 [0.8569464  0.1430536 ]
 [0.90314451 0.09685549]
 ...
 [0.98485732 0.01514268]
 [0.95472367 0.04527633]
 [0.61688623 0.38311377]]

Would appreciate any help. Thanks!

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.