Available with Spatial Analyst license.

## Summary

Performs Principal Component Analysis (PCA) on a set of raster bands and generates a single multiband raster as output.

## Usage

The value specified for the number of principal components determines the number of principal component bands in the output multiband raster. The number must not be larger than the total number of raster bands in the input.

The raster bands must have a common intersection. If there are none, an error occurs and no output is created.

The percent variance identifies the amount of the variance each eigenvalue captures. This can be useful to help interpret the results of PCA. If a few eigenvalues (each corresponding to bands in the output raster) capture the majority of the variance, it may be adequate to use this subset of bands in a subsequent analysis, since they may capture the majority of the interactions within the original multiband dataset.

When determining the percent variance each eigenvalue captures, the sum of eigenvalues is entered into the following formula: (eigenvalue * 100)/Sum. The first eigenvalue (and its associated band) captures the greatest variance, and the subsequent eigenvalues capture sequentially lesser variance. The accumulative percent of variance is a sequential sum of the variance each eigenvalue captures.

If the input is a layer created from a multiband raster with more than three bands, the operation will consider all the bands associated with the source dataset, not just the three bands that were loaded (symbolized) by the layer.

There are several ways you can specify a subset of bands from a multiband raster to use as input into the tool.

- If using the tool dialog box, browse to the multiband raster using the browse button next to Input raster bands, open the raster, and select the desired bands.
- If the multiband raster is a layer in the Table of Contents, you can use the Make Raster Layer tool to create a new multiband layer containing only the desired bands.
- You can also create a new dataset that contains only the desired bands with Composite Bands and use the resulting dataset as input to the tool.
- In Python, the desired bands can be directly specified in the tool parameter as a list.

See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

## Syntax

PrincipalComponents (in_raster_bands, {number_components}, {out_data_file})

Parameter | Explanation | Data Type |

in_raster_bands [in_raster_band,...] | The input raster bands. They can be integer or floating point type. | Raster Layer |

number_components (Optional) | Number of principal components. The number must be greater than zero and less than or equal to the total number of input raster bands. The default is the total number of rasters in the input. | Long |

out_data_file (Optional) | Output ASCII data file storing principal component parameters. The output data file records the correlation and covariance matrices, the eigenvalues and eigenvectors, the percent variance each eigenvalue captures, and the accumulative variance described by the eigenvalues. The extension for the output file can be .txt or .asc. | File |

### Return Value

Name | Explanation | Data Type |

out_multiband_raster | The output multiband raster dataset. If all of the input bands are integer type, the output raster bands will be integer. If any of the input bands are floating point, the output will be floating point. If the output is an Esri Grid raster, the name must have less than 10 characters. | Raster |

## Code Sample

##### PrincipalComponents example 1 (Python window)

This example performs Principal Component Analysis (PCA) on an input multiband raster and generates a multiband raster output.

```
import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outPrincipalComp = PrincipalComponents(["redlands"], 4,"pcdata.txt")
outPrincipalComp.save("C:/sapyexamples/output/outpc01")
```

##### PrincipalComponents example 2 (stand-alone script)

This example performs Principal Component Analysis (PCA) on an input multiband raster and generates a multiband raster output.

```
# Name: PrincipalComponents_Ex_02.py
# Description: Performs principal components analysis on a set of raster bands.
# Requirements: Spatial Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/sapyexamples/data"
# Set local variables
inRasterBand1 = "redlands/redlandsc1"
inRasterBand2 = "redlands/redlandsc3"
numberComponents = 2
outDataFile = "C:/sapyexamples/output/pcdatafile.txt"
# Check out the ArcGIS Spatial Analyst extension license
arcpy.checkOutExtension("Spatial")
# Execute PrincipalComponents
outPrincipalComp = PrincipalComponents([inRasterBand1, inRasterBand2], 2,
outDataFile)
# Save the output
outPrincipalComp.save("C:/sapyexamples/output/outpc01")
```

## Environments

## Licensing Information

- ArcGIS for Desktop Basic: Requires Spatial Analyst
- ArcGIS for Desktop Standard: Requires Spatial Analyst
- ArcGIS for Desktop Advanced: Requires Spatial Analyst