title: How can I implement my PCA results to my unlabelled data?
body: <p>I am struggling to implement my succesfull PCA.</p>
  <p>This is how my PCA plot looks like:</p>
  <p><a href="https://i.stack.imgur.com/0uH5Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0uH5Z.png" alt="enter image description here" /></a></p>
  <p>I retrieved this from accelerometer data (x, y, z) which I have observed and labeled with A, S and D.</p>
  <p>I can find a lot of information on the internet in how to perform a PCA but now I would like to implement it to my new data. And I cant find any information about that, or I am doing it all wrong.</p>
  <p>This is my code:</p>
  <pre><code>import pandas as pd
  import os
  from sklearn.preprocessing import StandardScaler
  import matplotlib.pyplot as plt
  from sklearn.decomposition import PCA
  
  os.chdir(r'C:\Users\##\OneDrive - ##\##\Pyth\data\runFlume1')
  os.getcwd()
  
  
  ## read csv
  df = pd.read_csv('dataframe_0.csv', delimiter=',', names = ['x','y','z','gradient_x','gradient_y','gradient_z','target'])
  
  
  features = ['x', 'y', 'z']
  
  # Separating out the features
  x = df.loc[:, features].values
  
  # Separating out the target
  y = df.loc[:,['target']].values
  
  # Standardizing the features
  x = StandardScaler().fit_transform(x)
  
  
  pca = PCA(n_components=2)
  principalComponents = pca.fit_transform(x)
  principalDf = pd.DataFrame(data = principalComponents
               , columns = ['principal component 1', 'principal component 2'])
  
  finalDf = pd.concat([principalDf, df[['target']]], axis = 1)
  
  fig = plt.figure(figsize = (8,8))
  ax = fig.add_subplot(1,1,1) 
  ax.set_xlabel('Principal Component 1', fontsize = 15)
  ax.set_ylabel('Principal Component 2', fontsize = 15)
  ax.set_title('2 component PCA', fontsize = 20)
  
  targets = ['A','S','D']
  colors = ['r', 'g', 'b']
  for target, color in zip(targets,colors):
      indicesToKeep = finalDf['target'] == target
      ax.scatter(finalDf.loc[indicesToKeep, 'principal component 1']
                 , finalDf.loc[indicesToKeep, 'principal component 2']
                 , c = color
                 , s = 50)
  ax.legend(targets)
  ax.grid()
  </code></pre>
  <p>And my raw dataframe looks like this:</p>
  <pre><code>       x      y      z  gradient_x  gradient_y  gradient_z target
  0     -0.875 -0.143  0.516      0.0310      0.0000       0.032      A
  1     -0.844 -0.143  0.548      0.0155      0.0000       0.000      A
  2     -0.844 -0.143  0.516      0.0000      0.0000       0.000      A
  3     -0.844 -0.143  0.548      0.0000      0.0000       0.016      A
  4     -0.844 -0.143  0.548      0.0000      0.0000       0.016      A
       ...    ...    ...         ...         ...         ...    ...
  17947  0.969 -0.079  0.161      0.0000      0.0475       0.016      D
  17948  1.000 -0.079  0.161      0.0000      0.0000       0.000      D
  17949  0.969 -0.079  0.161      0.0155      0.0000       0.000      D
  17950  0.969 -0.079  0.161      0.0000      0.0000       0.000      D
  17951  0.969 -0.079  0.161      0.0000      0.0000       0.000      D
  </code></pre>
  <p>So I would to like to use this PCA on data with no label (A,D,S). Does anyone know how I can do this?</p>
  <p>Kind regards,</p>
  <p>Simon</p>