Advertisement
lancernik

ADP

May 28th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue May 28 11:53:41 2019
  4.  
  5. @author: lancernik
  6. """
  7. #
  8. from sklearn.datasets.samples_generator import make_blobs
  9. from sklearn.cluster import SpectralClustering
  10. import numpy as np
  11. from sklearn.model_selection import train_test_split
  12. from sklearn.decomposition import PCA
  13. import pandas as pd
  14. X,y= make_blobs(n_samples=50, centers=5,random_state=0,n_features=15)
  15.  
  16.  
  17.  
  18.  
  19.  
  20. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
  21.  
  22. pca = PCA(n_components=7)
  23. principalComponents = pca.fit_transform(X)
  24. principalDf = pd.DataFrame(data = principalComponents
  25. , columns = ['1', '2','3','4','5','6','7'])
  26.  
  27.  
  28. print(pca.explained_variance_ratio_)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement