Hot answers tagged

5

Apparently this functionality is left out intentionally, see here. I'm afraid you have to use SVD, but that should be fairly straightforward: def pca(X): mean = X.mean(axis=0) center = X - mean _, stds, pcs = np.linalg.svd(center/np.sqrt(X.shape[0])) return stds**2, pcs


4

What can I do with this information? You can do a lot of things with this data. You can visualize it, you can use the vectors for prediction or regression, whatever the task at hand. However, there are a few restrictions of PCA that you need to keep in mind. For eg. its very memory intensive, so you need to have a "lot" of RAM to use PCA on certain data-...


4

No. t-Distributed Stochastic Neighbor Embedding (t-SNE) and Principal Component Analysis (PCA) are dimension reduction techniques, aka fewer columns of a tidy dataframe. Clustering will reduce the number of observations, aka fewer rows of a tidy dataframe. In particular, you might be looking for hierarchical clustering.


3

What I would suggest is to build a sklearn pipeline in which one step will be the sklearn PCA and the last step will be your Keras model. Sklearn pipelines are easy to put into production and can handle a lot more of transformations.


3

which is good for production They are both good. sklearn can be used in production as much as tensorflow.keras which will give me better and faster response I think that doesn't really depends on the libray, rather on the size of your models and of your datasets. That what really matters. Both modules can be used to create very optimized and fast models. ...


3

No, you can definitely search for k-NN with more than 2-dimension data. Here is an example based on sklearn: X = [[0, 0, 0], [3, 3, 3], [1, 2, 3]] from sklearn.neighbors import NearestNeighbors neigh = NearestNeighbors(n_neighbors=2) neigh.fit(X) print( neigh.kneighbors([[2,2,2]]) ) PCA is used to reduce the input dimensionality but this is not mandatory ...


2

There are two ways to perform the PCA: Compute the eigenvalue decomposition of the covariance matrix $\Sigma$ Compute the singular value decomposition of the data matrix $X$ Numerically, you can do both by calling svd() on either of them, as for positive semi-definite matrices (like $\Sigma$) svd() gives you the eigenvalue decomposition. There is a ...


2

PCA. Suppose that you have n data points comprised of d numbers (or dimensions) each. If you center this data (subtract the mean data point $\mu$ from each data vector $x_i$) you can stack the data to make a matrix $$ X = \left( \begin{array}{ccccc} && x_1^T - \mu^T && \\ \hline && x_2^T - \mu^T && \\ \hline &&...


2

Independent of the number of features, you will obviously need much more than 3 * 100.000 * 100.000 * 8 bytes of ram (with double precision floats). That is 240.000.000.000 or about 240 GB. Not only is this a lot of RAM to have, but AP will have to do many passes over this RAM, so this will take forever, even after computing the distance matrix. So ...


2

What is important is that the covariance matrix eigenvalues represent the variance explained by each component of the PCA. PCA can be considered useful when it allows to reduce the dimension without removing too much variance from the dataset; that is, when there are a lot of low eigenvalues. As the sum of the eigenvalues is fixed because it is the total ...


2

I think you may have forgotten to subtract the mean. As far as I know you have to center the data, otherwise you will compute variance with respect to the origin, rather than the variance within the data. Your data points have a mean vector $$\mu = \left[0, \frac{2}{3}\right] $$ Let's subtract the mean from the data and put it into a matrix $$ \tilde{X} =...


2

K-means don't modify the underlying structure of your data. K-means will just provide the 'color' part of your graph. To answer the question about why do you get a cuboid, it's because your underlying data are a cuboid. Not necessarily by construction, but that's what happen when you cap your data. As an exemple, look at the following code : X1 = c(rnorm(...


2

If you want to reduce the number of classes you are predicting over, then you could manually map them to a simpler set (i.e. map poodle, greyhound to dog ) OR if you don't have the domain knowledge you can cluster your data and predict the cluster instead of their original labels. You could use PCA or t-SNE to reduce the number of dimensions before ...


2

I highly recommend using PlotlyExpress instead This code is plotting the first 3 components on the iris dataset import plotly.express as px from sklearn.datasets import load_iris from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler, FunctionTransformer from sklearn.pipeline import Pipeline X, y = ...


2

Instead of using the score method on your trained model, you should use the predict method. You can then pass the results into the confusion matrix function from sklearn: from sklearn.metrics import confusion_matrix y_pred = svmObject.predict(X) cm = confusion_matrix(y_true, y_pred, sample_weight=sample_weight, labels=labels, ...


2

Note that doing a dimensionality reduction with the target can lead you to the manifold problem. You can see in the image. What ends up happening is that the target information is lost. The information that you provide is not enough to make a guess of what algorithm will be better. Normally reducing the dimensionality of the problem to a lower dimension ...


2

My answer would be second option I think the use of PCA is to represent original high dimensional information/data in lower dimension by calculationg the direction/axes along which there is maximum variablity in data. In first case, where you filter for 0-labeled observations and then do PCA so PCA would measure variablity based on a smaller version of ...


1

I assume you applied SVM to your initial data and use PCA only for visualization. I this case: I guess your projection via the PCA is not showing the real picture. You should check first how much of your data is explained with the first two principal components of the PCA. Your projection might change to much the structure of your data so that its not ...


1

The ranking is derived form the size of the eigenvalue of the principal component (largest on top) and the scores represent 1 - cumulative sum of the variance.


1

PCA is not recommended for categorical features. There are equivalent algorithms for categorical features like CATPCA and MCA.


1

You can use mini batch PCA. One formulation is available in sklearn. Alternatively, you can run PCA on a carefully selected subset of your data. It's very time consuming and I'm not sure it's possible, and its feasibility is task specific.


1

Concerning the dimensionality reduction I encourage you to check non-linear dimensionality reduction if PCA do does not give satisfying results. It can happen that some low dimensionality manifold hides behind a much higher number of features. The excellent sklearn's guide explains manifold learning in detail. Concerning the algorithm Almost any algorithm ...


1

Variations of PCA can still be applicable. If the data is not linear, use nonlinear PCA. It is not an issue there a multiple "y"s for every "x". PCA is unsupervised, there is no notion of targets. In PCA, there are only dimensions. Typically, the dimensions are standardized so each dimension can be weighted independent of scale. One caveat - PCA is ...


1

Do I use the mean vector from my training set to center my testing set when dimension reducing for classification?: Yes. Test set must not be combined with training set in any step of calculating the reduced dimension space. Characteristics of final space is determined by training set and test set just follows that i.e. the mean-adjusting step uses ...


1

PCA does not throw away the unimportant features. In other words, features that you get from PCA are not the original ones. Mathematically PCA is orthogonal linear transformation that transforms the data to a new coordinate system such that the greatest variance by some scalar projection of the data comes to lie on the first coordinate (called the first ...


1

A lot of the values from your data seem to be of the same size, or very small difference, also it seems it is important to deal with noise. The same problem is true for image compression. I think a good approach would be to use Haar-Wavelet Transform which compresses the information by a very huge amount and reduces the noisy data, like it does for image ...


1

First of all, you can project your explanatory variable (continuous) in your first plane (PC1 + PC2). The direction of the arrow (projection) and how far goes from the axis origin will tell you how the points are distributed according to this representation of variables in your factorial plane. On the other hand, the quick answer is to group your continuous ...


1

PCA and truncate SVD do not differ much, since they are based on the same theory that the eigenvectors with the less eigenvalue are discarded. As mentioned here the difference: TruncatedSVD is very similar to PCA, but differs in that it works on sample matrices directly instead of their covariance matrices. When the columnwise (per-feature) means of are ...


1

When you do PCA to project your problem two a 'n' dimensional space, in your case 2 dimensions. So you are fitting a model with just two features. If you print your variable 'explained_variance' you will see the percentage of variance respect to the total that you have. Ideas to improve your model: search for hyperparameters, do target encoding instead ...


1

Being PCA the same as SVD, I'll explain the approach with the last one. SVD decomposes a matrix $A$ in three others, so that $A = U * \Sigma * V^t$, where $\Sigma$ is diagonal consisting of $A$'s singular values in descending order. The sum of all the singular values of $A$ is known as energy of matrix $A$. You want to retain most of the matrix's energy ...


Only top voted, non community-wiki answers of a minimum length are eligible