How to extract features using PCA in Python?
FEATURE EXTRACTION

How to extract features using PCA in Python?

How to extract features using PCA in Python?

This recipe helps you extract features using PCA in Python

1
This data science python source code does the following: 1. Implements Standard scaler function. 2. Implements PCA to reduces dimensions. 3. Reducing time complexity using PCA. 4. Selecting optimum number of dimensions
In [1]:
## How to extract features using PCA in Python
def Snippet_124():
    print()
    print(format('How to extract features using PCA in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn import decomposition, datasets
    from sklearn.preprocessing import StandardScaler

    # Load the breast cancer dataset
    dataset = datasets.load_breast_cancer()

    # Load the features
    X = dataset.data

    # View the shape of the dataset
    print(); print(X.shape)
    print(); print(X)

    # Standardize Features
    sc = StandardScaler()

    # Fit the scaler to the features and transform
    X_std = sc.fit_transform(X)

    # View the new feature data's shape    
    print(); print(X_std.shape)
    print(); print(X_std)

    # Create a pca object with the 3 components
    pca = decomposition.PCA(n_components=3)

    # Fit the PCA and transform the data
    X_std_pca = pca.fit_transform(X_std)

    # View the new feature data's shape
    print(); print(X_std_pca.shape)
    print(); print(X_std_pca)

Snippet_124()
*******************How to extract features using PCA in Python********************

(569, 30)

[[1.799e+01 1.038e+01 1.228e+02 ... 2.654e-01 4.601e-01 1.189e-01]
 [2.057e+01 1.777e+01 1.329e+02 ... 1.860e-01 2.750e-01 8.902e-02]
 [1.969e+01 2.125e+01 1.300e+02 ... 2.430e-01 3.613e-01 8.758e-02]
 ...
 [1.660e+01 2.808e+01 1.083e+02 ... 1.418e-01 2.218e-01 7.820e-02]
 [2.060e+01 2.933e+01 1.401e+02 ... 2.650e-01 4.087e-01 1.240e-01]
 [7.760e+00 2.454e+01 4.792e+01 ... 0.000e+00 2.871e-01 7.039e-02]]

(569, 30)

[[ 1.09706398 -2.07333501  1.26993369 ...  2.29607613  2.75062224
   1.93701461]
 [ 1.82982061 -0.35363241  1.68595471 ...  1.0870843  -0.24388967
   0.28118999]
 [ 1.57988811  0.45618695  1.56650313 ...  1.95500035  1.152255
   0.20139121]
 ...
 [ 0.70228425  2.0455738   0.67267578 ...  0.41406869 -1.10454895
  -0.31840916]
 [ 1.83834103  2.33645719  1.98252415 ...  2.28998549  1.91908301
   2.21963528]
 [-1.80840125  1.22179204 -1.81438851 ... -1.74506282 -0.04813821
  -0.75120669]]

(569, 3)

[[ 9.19283683  1.94858275 -1.123163  ]
 [ 2.38780181 -3.76817263 -0.52928187]
 [ 5.73389628 -1.07517383 -0.55174676]
 ...
 [ 1.25617927 -1.90229641  0.56272681]
 [10.37479405  1.67201091 -1.87703905]
 [-5.47524329 -0.67063731  1.49044953]]

Relevant Projects

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Anomaly Detection Using Deep Learning and Autoencoders
Deep Learning Project- Learn about implementation of a machine learning algorithm using autoencoders for anomaly detection.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.