Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3251be

Browse files
committed
Remove mlab.PCA
1 parent 7d03bf5 commit d3251be

File tree

3 files changed

+1
-145
lines changed

3 files changed

+1
-145
lines changed

doc/api/next_api_changes/2018-09-18-DS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ in Matplotlib 2.2 has been removed. See below for a list:
1111
- `mlab.find` (use ``np.nonzero(np.ravel(condition))`` instead)
1212
- `mlab.longest_contiguous_ones`
1313
- `mlab.longest_ones`
14+
- `mlab.PCA`
1415
- `mlab.donothing_callback`

lib/matplotlib/mlab.py

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,142 +1194,6 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none, window=window_hanning,
11941194
return Cxy, f
11951195

11961196

1197-
@cbook.deprecated('2.2')
1198-
class PCA(object):
1199-
def __init__(self, a, standardize=True):
1200-
"""
1201-
compute the SVD of a and store data for PCA. Use project to
1202-
project the data onto a reduced set of dimensions
1203-
1204-
Parameters
1205-
----------
1206-
a : np.ndarray
1207-
A numobservations x numdims array
1208-
standardize : bool
1209-
True if input data are to be standardized. If False, only centering
1210-
will be carried out.
1211-
1212-
Attributes
1213-
----------
1214-
a
1215-
A centered unit sigma version of input ``a``.
1216-
1217-
numrows, numcols
1218-
The dimensions of ``a``.
1219-
1220-
mu
1221-
A numdims array of means of ``a``. This is the vector that points
1222-
to the origin of PCA space.
1223-
1224-
sigma
1225-
A numdims array of standard deviation of ``a``.
1226-
1227-
fracs
1228-
The proportion of variance of each of the principal components.
1229-
1230-
s
1231-
The actual eigenvalues of the decomposition.
1232-
1233-
Wt
1234-
The weight vector for projecting a numdims point or array into
1235-
PCA space.
1236-
1237-
Y
1238-
A projected into PCA space.
1239-
1240-
Notes
1241-
-----
1242-
The factor loadings are in the ``Wt`` factor, i.e., the factor loadings
1243-
for the first principal component are given by ``Wt[0]``. This row is
1244-
also the first eigenvector.
1245-
1246-
"""
1247-
n, m = a.shape
1248-
if n < m:
1249-
raise RuntimeError('we assume data in a is organized with '
1250-
'numrows>numcols')
1251-
1252-
self.numrows, self.numcols = n, m
1253-
self.mu = a.mean(axis=0)
1254-
self.sigma = a.std(axis=0)
1255-
self.standardize = standardize
1256-
1257-
a = self.center(a)
1258-
1259-
self.a = a
1260-
1261-
U, s, Vh = np.linalg.svd(a, full_matrices=False)
1262-
1263-
# Note: .H indicates the conjugate transposed / Hermitian.
1264-
1265-
# The SVD is commonly written as a = U s V.H.
1266-
# If U is a unitary matrix, it means that it satisfies U.H = inv(U).
1267-
1268-
# The rows of Vh are the eigenvectors of a.H a.
1269-
# The columns of U are the eigenvectors of a a.H.
1270-
# For row i in Vh and column i in U, the corresponding eigenvalue is
1271-
# s[i]**2.
1272-
1273-
self.Wt = Vh
1274-
1275-
# save the transposed coordinates
1276-
Y = np.dot(Vh, a.T).T
1277-
self.Y = Y
1278-
1279-
# save the eigenvalues
1280-
self.s = s**2
1281-
1282-
# and now the contribution of the individual components
1283-
vars = self.s / len(s)
1284-
self.fracs = vars/vars.sum()
1285-
1286-
def project(self, x, minfrac=0.):
1287-
'''
1288-
project x onto the principle axes, dropping any axes where fraction
1289-
of variance<minfrac
1290-
'''
1291-
x = np.asarray(x)
1292-
if x.shape[-1] != self.numcols:
1293-
raise ValueError('Expected an array with dims[-1]==%d' %
1294-
self.numcols)
1295-
Y = np.dot(self.Wt, self.center(x).T).T
1296-
mask = self.fracs >= minfrac
1297-
if x.ndim == 2:
1298-
Yreduced = Y[:, mask]
1299-
else:
1300-
Yreduced = Y[mask]
1301-
return Yreduced
1302-
1303-
def center(self, x):
1304-
'''
1305-
center and optionally standardize the data using the mean and sigma
1306-
from training set a
1307-
'''
1308-
if self.standardize:
1309-
return (x - self.mu)/self.sigma
1310-
else:
1311-
return (x - self.mu)
1312-
1313-
@staticmethod
1314-
def _get_colinear():
1315-
c0 = np.array([
1316-
0.19294738, 0.6202667, 0.45962655, 0.07608613, 0.135818,
1317-
0.83580842, 0.07218851, 0.48318321, 0.84472463, 0.18348462,
1318-
0.81585306, 0.96923926, 0.12835919, 0.35075355, 0.15807861,
1319-
0.837437, 0.10824303, 0.1723387, 0.43926494, 0.83705486])
1320-
1321-
c1 = np.array([
1322-
-1.17705601, -0.513883, -0.26614584, 0.88067144, 1.00474954,
1323-
-1.1616545, 0.0266109, 0.38227157, 1.80489433, 0.21472396,
1324-
-1.41920399, -2.08158544, -0.10559009, 1.68999268, 0.34847107,
1325-
-0.4685737, 1.23980423, -0.14638744, -0.35907697, 0.22442616])
1326-
1327-
c2 = c0 + 2*c1
1328-
c3 = -3*c0 + 4*c1
1329-
a = np.array([c3, c0, c1, c2]).T
1330-
return a
1331-
1332-
13331197
@cbook.deprecated('2.2', 'numpy.percentile')
13341198
def prctile(x, p=(0.0, 25.0, 50.0, 75.0, 100.0)):
13351199
"""

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
'''
2121

2222

23-
def test_colinear_pca():
24-
with pytest.warns(MatplotlibDeprecationWarning):
25-
a = mlab.PCA._get_colinear()
26-
pca = mlab.PCA(a)
27-
28-
assert_allclose(pca.fracs[2:], 0., atol=1e-8)
29-
assert_allclose(pca.Y[:, 2:], 0., atol=1e-8)
30-
31-
3223
@pytest.mark.parametrize('input', [
3324
# test odd lengths
3425
[1, 2, 3],

0 commit comments

Comments
 (0)