---
title: "CentralFeature"
language: "en"
type: "Symbol"
summary: "CentralFeature[{x1, x2, ...}] gives the central feature of the elements xi. CentralFeature[{x1 -> v1, x2 -> v2, ...}] gives the vi corresponding to the central feature xi. CentralFeature[data] gives the central feature for several different forms of data."
keywords: 
- central feature
- central tendency
- location estimator
canonical_url: "https://reference.wolfram.com/language/ref/CentralFeature.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Descriptive Statistics"
    link: "https://reference.wolfram.com/language/guide/DescriptiveStatistics.en.md"
  - 
    title: "Locations, Paths, and Routing"
    link: "https://reference.wolfram.com/language/guide/LocationsPathsAndRouting.en.md"
  - 
    title: "Spatial Point Collections"
    link: "https://reference.wolfram.com/language/guide/SpatialPointCollections.en.md"
  - 
    title: "Spatial Statistics"
    link: "https://reference.wolfram.com/language/guide/SpatialStatistics.en.md"
  - 
    title: "Distance and Similarity Measures"
    link: "https://reference.wolfram.com/language/guide/DistanceAndSimilarityMeasures.en.md"
  - 
    title: "Robust Descriptive Statistics"
    link: "https://reference.wolfram.com/language/guide/RobustDescriptiveStatistics.en.md"
related_functions: 
  - 
    title: "Mean"
    link: "https://reference.wolfram.com/language/ref/Mean.en.md"
  - 
    title: "Median"
    link: "https://reference.wolfram.com/language/ref/Median.en.md"
  - 
    title: "TrimmedMean"
    link: "https://reference.wolfram.com/language/ref/TrimmedMean.en.md"
  - 
    title: "WinsorizedMean"
    link: "https://reference.wolfram.com/language/ref/WinsorizedMean.en.md"
  - 
    title: "BiweightLocation"
    link: "https://reference.wolfram.com/language/ref/BiweightLocation.en.md"
  - 
    title: "SpatialMedian"
    link: "https://reference.wolfram.com/language/ref/SpatialMedian.en.md"
  - 
    title: "GraphCenter"
    link: "https://reference.wolfram.com/language/ref/GraphCenter.en.md"
  - 
    title: "DistanceMatrix"
    link: "https://reference.wolfram.com/language/ref/DistanceMatrix.en.md"
---
# CentralFeature

CentralFeature[{x1, x2, …}] gives the central feature of the elements $x_i$.

CentralFeature[{x1 -> v1, x2 -> v2, …}] gives the vi corresponding to the central feature $x_i$.

CentralFeature[data] gives the central feature for several different forms of data.

## Details and Options

* ``CentralFeature`` is a location measure. It gives a point in the data with the minimum total distance to every other point.

* ``CentralFeature`` finds the element $x^*\in \left\{x_1,x_2,\text{...}\right\}$ that minimizes the sum of distances $\sum _{i=1}^n d\left(x^*,x_i\right)$ for the unweighted case and $\sum _{i=1}^n w_id\left(x^*,x_i\right)$ for the weighted case.

[image]

* The data ``data`` has the following forms and interpretations:

|     |     |
| --- | --- |
| {data1, data2, …} | list of data of different formats including numerical, geospatial, textual, visual, dates and times, as well as combinations of these |
| {data1, data2, …} -> {v1, v2, …} | data with indices {v1, v2, …} |
| {data1, data2, …} -> Automatic | take the vi to be successive integers i  |
| GeoPosition[…] | array of geodetic positions |
| WeightedData[…] | data with weights |

* The following option can be given:

[`DistanceFunction`](https://reference.wolfram.com/language/ref/DistanceFunction.en.md) 	[`Automatic`](https://reference.wolfram.com/language/ref/Automatic.en.md)	the distance metric to use

* The setting for ``DistanceFunction`` can be any distance or dissimilarity function or a function ``f`` defining a distance between two points.

* By default, the following distance functions are used for different types of elements:

|                              |                            |
| ---------------------------- | -------------------------- |
| EuclideanDistance            | numeric data               |
| ImageDistance                | images                     |
| JaccardDissimilarity         | Boolean data               |
| EditDistance                 | text and nominal sequences |
| Abs[DateDifference[#1, #2]]& | dates and times            |
| ColorDistance                | colors                     |
| GeoDistance                  | geospatial data            |
| Boole[SameQ[#1, #2]]&        | nominal data               |
| HammingDistance              | nominal vector data        |
| WarpingDistance              | numerical sequences        |

* All images are first conformed using ``ConformImages`` when the option ``DistanceFunction`` is ``Automatic``.

* By default, when data elements are mixed-type vectors, distances are computed independently for each type and combined using ``Norm``.

---

## Examples (23)

### Basic Examples (2)

Find the central feature in a list of vectors:

```wl
In[1]:= CentralFeature[{{1., 3., 5.}, {7., 1., 2.}, {9., 3., 1.}, {4., 5., 6.}}]

Out[1]= {7., 1., 2.}
```

---

Find the central feature in a list of vectors with given weights:

```wl
In[1]:= CentralFeature[WeightedData[{{1., 3., 5.}, {-4., 1., 2.}, {3., 3., 1.}, {4., 5., 6.}}, {1., 3., 4., 5.}]]

Out[1]= {3., 3., 1.}
```

### Scope (9)

Same inputs with different output formats:

```wl
In[1]:= data = {{1, 2}, {3, 4}, {8, 7}, {6, 5}, {9, 4}, {1, 3}};

In[2]:= CentralFeature[data]

Out[2]= {3, 4}

In[3]:= CentralFeature[data -> Automatic]

Out[3]= 2

In[4]:= CentralFeature[data -> Table[f[i], {i, 6}]]

Out[4]= f[2]

In[5]:= CentralFeature[{{1, 2} -> g[1], {3, 4} -> g[2], {8, 7} -> g[3], {6, 5} -> g[4], {9, 4} -> g[5], {1, 3} -> g[6]}]

Out[5]= g[2]
```

---

Central feature works with ``WeightedData`` :

```wl
In[1]:= wd = WeightedData[{{1., 3.}, {-4., 2.}, {3., 1.}, {5., 6.}}, {1., 3., 4., 5.}];

In[2]:= CentralFeature[wd]

Out[2]= {3., 1.}

In[3]:= CentralFeature[wd -> {1, 2, 3, 4}]

Out[3]= 3
```

---

Central feature of a large array:

```wl
In[1]:= CentralFeature[RandomReal[1, {10 ^ 5, 2}]]

Out[1]= {0.501217, 0.500012}
```

Weighted central feature:

```wl
In[2]:= CentralFeature[WeightedData[RandomReal[1, {10 ^ 5, 3}], RandomReal[1, 10 ^ 5]]]

Out[2]= {0.492451, 0.492348, 0.502146}
```

---

Find the central feature of data involving quantities:

```wl
In[1]:= data = Quantity[RandomReal[1, {6, 2}], "Meters"]

Out[1]= {{Quantity[0.11079720282181693, "Meters"], Quantity[0.6515314303412563, "Meters"]}, {Quantity[0.49613268680883627, "Meters"], Quantity[0.8521439683724525, "Meters"]}, {Quantity[0.07466180322204763, "Meters"], Quantity[0.3659169954207231, "Meters"]}, {Quantity[0.29822857534926706, "Meters"], Quantity[0.3699025216424252, "Meters"]}, {Quantity[0.23107340697669554, "Meters"], Quantity[0.8761732437389362, "Meters"]}, {Quantity[0.41766891691505825, "Meters"], Quantity[0.9796850527424898, "Meters"]}}

In[2]:= CentralFeature[data]

Out[2]= {Quantity[0.11079720282181693, "Meters"], Quantity[0.6515314303412563, "Meters"]}
```

---

Find the central feature of a list of images:

```wl
In[1]:= CentralFeature[{[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}]

Out[1]= [image]
```

List of pictures:

```wl
In[2]:= CentralFeature[{[image], [image], [image], [image], [image], [image]}]

Out[2]= [image]
```

List of 3D images:

```wl
In[3]:= CentralFeature[{[image], [image], [image], [image], [image]}]

Out[3]= [image]
```

---

Compute the central feature of strings:

```wl
In[1]:= CentralFeature[{"abcd", "bcde", "abab", "abcdef", "agi"}]

Out[1]= "abcd"
```

---

Compute the central feature of Boolean vectors:

```wl
In[1]:= CentralFeature[{{True, False, True}, {True, True, True}, {True, False, False}, {False, False, False}}]

Out[1]= {True, False, True}
```

---

Compute the central feature of a list of date objects:

```wl
In[1]:= CentralFeature[{DateObject[{1985, 10, 3}], DateObject[{1989, 5, 30}], DateObject[{1999, 11, 15}], DateObject[]}]

Out[1]= DateObject[{1989, 5, 30}, "Day", "Gregorian", -6.]
```

---

Compute the central feature of geodetic positions:

```wl
In[1]:= cities = {Entity["City", {"Paris", "IleDeFrance", "France"}], Entity["City", {"Sydney", "NewSouthWales", "Australia"}], Entity["City", {"Boston", "Massachusetts", "UnitedStates"}], Entity["City", {"SanFrancisco", "California", "UnitedStates"}], Entity["City", {"Tokyo", "Tokyo", "Japan"}]};

In[2]:= cf = CentralFeature[GeoPosition[cities]]

Out[2]= GeoPosition[{37.7599, -122.437}]

In[3]:= GeoGraphics[{GeoPath[Thread[{cf, cities}]], GeoMarker[cities, Gray], GeoMarker[cf, Red]}, GeoProjection -> {"AzimuthalEquidistant", "Centering" -> cf}, GeoRange -> "World", GeoGridLines -> Automatic]

Out[3]= [image]
```

### Options (2)

#### DistanceFunction (2)

By default, Euclidean distance is used:

```wl
In[1]:= CentralFeature[RandomVariate[NormalDistribution[], {10, 3}]]

Out[1]= {-0.813317, 0.390383, -0.572312}
```

The ``ChessboardDistance`` only takes into account the dimension with the largest separation:

```wl
In[2]:= CentralFeature[{{1., 3.}, {-2.6, 4.}, {9.2, 5.}, {7.3, -5.}}, DistanceFunction -> ChessboardDistance]

Out[2]= {1., 3.}
```

---

The ``DistanceFunction`` can be given as a symbol:

```wl
In[1]:= dist[{u_, v_}, {x_, y_}] := Sqrt[3(u - x) ^ 2 + 2(v - y) ^ 2]

In[2]:= data = {{1.5, .6}, {2, 0}, {1.25, 1.25}, {3., 0.3}};

In[3]:= CentralFeature[data, DistanceFunction -> dist]

Out[3]= {1.5, 0.6}
```

Or as a pure function:

```wl
In[4]:= CentralFeature[data, DistanceFunction -> (Sqrt[{3, 2}.(#1 - #2) ^ 2]&)]

Out[4]= {1.5, 0.6}
```

### Applications (4)

Obtain a robust estimate of multivariate location when outliers are present:

```wl
In[1]:= data = {{3., -5.}, {2., -5.}, {0., 2.}, {-4., -3.}, {10 ^ 8, -1.}, {8., -20000}};

In[2]:= CentralFeature[data]

Out[2]= {2., -5.}
```

Extreme values have a large influence on the ``Mean`` :

```wl
In[3]:= Mean[data]

Out[3]= {1.6666668166666666*^7, -3335.33}
```

---

Sample points from a convex polygon:

```wl
In[1]:=
poly = Polygon[{{2., -5.}, {0., 2.}, {-4., -3.}, {-5, -7}}];
pts = RandomPoint[poly, 10 ^ 3];

In[2]:= Graphics[{Lighter[Blue, .9], poly, Black, PointSize[Small], Point[pts]}]

Out[2]= [image]
```

Estimate the center of the polygon by computing the central feature of random points:

```wl
In[3]:= cf = CentralFeature[pts]

Out[3]= {-1.28721, -3.29255}

In[4]:= Graphics[{Lighter[Blue, .9], poly, Black, PointSize[Small], Point[pts], PointSize[0.06], Red, Point[cf]}]

Out[4]= [image]
```

---

Find the central feature of California, based on the location of cities:

```wl
In[1]:=
cities = CityData[{All, "California"}];
locations = GeoPosition[CityData[#, "Coordinates"]& /@ cities];

In[2]:= unweighted = cities[[CentralFeature[locations -> Automatic]]]

Out[2]= Entity["City", {"McSwain", "California", "UnitedStates"}]
```

Find the central feature of California, based on the location of cities weighted by population:

```wl
In[3]:= populations = CityData[#, "Population"]& /@ cities;

In[4]:= weighted = cities[[CentralFeature[WeightedData[locations, populations] -> Automatic]]]

Out[4]= Entity["City", {"Burbank", "California", "UnitedStates"}]
```

Draw the cities' locations (gray), unweighted central feature (red) and weighted central feature (black):

```wl
In[5]:= legend = PointLegend[{Red, Blue}, {"unweighted central feature", "central feature weighted by population"}, LegendMarkerSize -> Large];

In[6]:= Legended[GeoGraphics[{EdgeForm[Black], FaceForm[Orange], Polygon[Entity["AdministrativeDivision", {"California", "UnitedStates"}]], GrayLevel[.4], PointSize[0.0075], Point[locations], PointSize[0.04], Red, Point[unweighted], Blue, Point[weighted]}, GeoRange -> {{32, 43}, {-125, -114}}, ImageSize -> 350], Placed[legend, "Bottom"]]

Out[6]= [image]
```

---

The top eight largest cities in Ohio:

```wl
In[1]:= cities = CityData[{Large, "Ohio"}]

Out[1]= {Entity["City", {"Columbus", "Ohio", "UnitedStates"}], Entity["City", {"Cleveland", "Ohio", "UnitedStates"}], Entity["City", {"Cincinnati", "Ohio", "UnitedStates"}], Entity["City", {"Toledo", "Ohio", "UnitedStates"}], Entity["City", {"Akron", "Ohio", "UnitedStates"}], Entity["City", {"Dayton", "Ohio", "UnitedStates"}]}
```

The central feature of the eight cities based on ``TravelDistance`` :

```wl
In[2]:= center = CentralFeature[cities, DistanceFunction -> TravelDistance]

Out[2]= Entity["City", {"Columbus", "Ohio", "UnitedStates"}]
```

The sum of distances from the central feature to the other cities, based on ``TravelDistance`` :

```wl
In[3]:= Total[Table[TravelDistance[center, city], {city, cities}]]

Out[3]= Quantity[3.1049121030183723*^6, "Feet"]
```

Draw the cities' locations (gray) and the central feature (red):

```wl
In[4]:= GeoGraphics[{EdgeForm[Black], FaceForm[Orange], Polygon[Entity["AdministrativeDivision", {"Ohio", "UnitedStates"}]], Red, TravelDirections[{center, #}, "TravelPath"]& /@ cities, GrayLevel[.4], PointSize[0.03], Point /@ cities, PointSize[0.03], Red, Point[center]}]

Out[4]= [image]
```

### Properties & Relations (5)

``CentralFeature`` is a multivariate location measure:

```wl
In[1]:= pts = {{3, -5}, {2, -5}, {0, 2}, {-4, -3}, {-3, 2}, {-5, -5}, {-1, -5}, {-1, -5}, {5, -1}, {-3, 3}, {10, -1}, {8, -2}};

In[2]:= Graphics[{PointSize[0.03], Orange, Point[pts]}]

Out[2]= [image]

In[3]:= cf = CentralFeature[pts]

Out[3]= {-1, -5}
```

``Mean`` is also a location measure:

```wl
In[4]:= mean = Mean[pts]

Out[4]= {(11/12), -(25/12)}
```

Visualize the data points with central feature and mean:

```wl
In[5]:= Graphics[{PointSize[0.03], Orange, Point[pts], Locator[cf], Blue, PointSize[.04], Point[mean], Gray, Text["Central Feature", cf - {0, .8}], Text["Mean", mean + {0, .8}]}, ImageSize -> 250]

Out[5]= [image]
```

---

``CentralFeature`` finds a point belonging to the data that minimizes the sum of distances:

```wl
In[1]:= data = {{1., 3.}, {4., 6.}, {9., 2.}, {5., 5.}, {7., -2.}};

In[2]:= cf = CentralFeature[data]

Out[2]= {5., 5.}
```

Compute the central feature directly from the definition:

```wl
In[3]:= sumofdists[x_, y_] := Total[Sqrt[Total[(Transpose[data] - {x, y}) ^ 2]]]

In[4]:=
{ind} = Ordering[sumofdists@@@data, 1];
data[[ind]]

Out[4]= {5., 5.}
```

Visualize the sum of distances function together with the data points:

```wl
In[5]:=
sumofdists = Total[Sqrt[Total[(Transpose[data] - {#1, #2}) ^ 2]]]&;
ContourPlot[sumofdists[x, y], {x, 0, 10}, {y, -3, 8}, Contours -> 10, PlotLegends -> Automatic, Epilog -> {PointSize[Large], Black, Point[data], Red, PointSize[Large], Point[cf], White, Text["Central Feature", cf - {0, 0.7}]}]

Out[5]= [image]
```

---

``CentralFeature`` is the same as ``Median`` with univariate data when the data length is odd:

```wl
In[1]:= data = RandomReal[1, 1001];

In[2]:= CentralFeature[data] == Median[data]

Out[2]= True
```

---

``CentralFeature`` finds an element in the data that minimizes the sum of distances to other data points:

```wl
In[1]:= data = RandomVariate[NormalDistribution[], {10, 3}];

In[2]:= MemberQ[data, CentralFeature[data]]

Out[2]= True
```

``SpatialMedian`` finds a point in the domain that minimizes the sum of distances:

```wl
In[3]:= MemberQ[data, SpatialMedian[data]]

Out[3]= False
```

The sum of distances with respect to ``CentralFeature`` is greater than or equal to the one with respect to ``SpatialMedian`` :

```wl
In[4]:= sumofdists = Total[Sqrt[Total[(Transpose[data] - #) ^ 2]]]&;

In[5]:= sumofdists[CentralFeature[data]] ≥ sumofdists[SpatialMedian[data]]

Out[5]= True
```

---

Create a random graph with edge weights sampled uniformly between 0 and 1:

```wl
In[1]:=
SeedRandom[7];
graph = RandomGraph[{10, 15}, EdgeWeight -> RandomReal[1, 15]]

Out[1]= [image]
```

Locate the ``GraphCenter`` :

```wl
In[2]:= GraphCenter[graph]

Out[2]= {4}
```

Specify the distance between each pair of vertices using ``GraphDistance`` :

```wl
In[3]:= distfun = GraphDistance[graph, #1, #2]&;
```

Locate the center using ``CentralFeature`` :

```wl
In[4]:= CentralFeature[Range[10], DistanceFunction -> distfun]

Out[4]= 4
```

### Possible Issues (1)

``CentralFeature`` of a non-weighted, two-element list returns the first element:

```wl
In[1]:= data = {GeoPosition[{20, -30}], GeoPosition[{15, 15}]};

In[2]:= CentralFeature[data]

Out[2]= GeoPosition[{20, -30}]
```

For weighted two-element lists, it chooses the element with the highest weight, which trivially minimizes  $\sum _{i=1}^n w_id\left(x^*,x_i\right)$ :

```wl
In[3]:= CentralFeature[WeightedData[data, {1, 2}]]

Out[3]= GeoPosition[{15, 15}]
```

## See Also

* [`Mean`](https://reference.wolfram.com/language/ref/Mean.en.md)
* [`Median`](https://reference.wolfram.com/language/ref/Median.en.md)
* [`TrimmedMean`](https://reference.wolfram.com/language/ref/TrimmedMean.en.md)
* [`WinsorizedMean`](https://reference.wolfram.com/language/ref/WinsorizedMean.en.md)
* [`BiweightLocation`](https://reference.wolfram.com/language/ref/BiweightLocation.en.md)
* [`SpatialMedian`](https://reference.wolfram.com/language/ref/SpatialMedian.en.md)
* [`GraphCenter`](https://reference.wolfram.com/language/ref/GraphCenter.en.md)
* [`DistanceMatrix`](https://reference.wolfram.com/language/ref/DistanceMatrix.en.md)

## Related Guides

* [Descriptive Statistics](https://reference.wolfram.com/language/guide/DescriptiveStatistics.en.md)
* [Locations, Paths, and Routing](https://reference.wolfram.com/language/guide/LocationsPathsAndRouting.en.md)
* [Spatial Point Collections](https://reference.wolfram.com/language/guide/SpatialPointCollections.en.md)
* [Spatial Statistics](https://reference.wolfram.com/language/guide/SpatialStatistics.en.md)
* [Distance and Similarity Measures](https://reference.wolfram.com/language/guide/DistanceAndSimilarityMeasures.en.md)
* [Robust Descriptive Statistics](https://reference.wolfram.com/language/guide/RobustDescriptiveStatistics.en.md)

## History

* [Introduced in 2017 (11.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn111.en.md)