rasbt / python-machine-learning-book

The "Python Machine Learning (1st edition)" book code repository and info resource
MIT License
12.18k stars 4.39k forks source link

IndexError: too many indices for array in CH-5 PCA Plot Code #82

Closed somesh636 closed 4 years ago

somesh636 commented 4 years ago

I am having an issue in executing the for generating the graph of the PCA in Chapter-5 of the book Python Machine Learning. I tried debugging but I am not able to understand what the problem in the code is. issue1 Kindly provide support for this issue.

rasbt commented 4 years ago

There error means that X_train_pca has either 0 or 1 dimensions, instead of 2, or there is only 1 column instead of 2. You can double-check by executing print(X_train_pca.shape) before the for loop. The returned tuple should have at least 2 numbers, where the second number should be a 2.

This if you see that X_train_pca.shape is not (100, 2), then there is a typo somewhere in your preceding code.

somesh636 commented 4 years ago

Thank you for your quick response. There was a typo in the code. This book is really good for understanding the Machine learning concepts.

rasbt commented 4 years ago

glad to hear that you found and fixed it!