Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,505 changes: 1,505 additions & 0 deletions Phase 3 - 2020 (Summer)/Korada Pavan Kumar_190108028/exercise11.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@


from matplotlib import pyplot as plt
import pandas as pd
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler


# Code is written to find out the pca graph of ten dimensional data given

df = pd.read_csv('data.txt',delimiter='\t', names=['Label', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10'])

features = ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10']
x =df.loc[:, features].values
y = df.loc[:, ['Label']].values
x = StandardScaler().fit_transform(x)
#print(pd.DataFrame(data = x, columns = features).head())

pca = PCA(n_components =2)
principalComponents = pca.fit_transform(x)
principalDf =pd.DataFrame(data = principalComponents
, columns =['principal component 1','principal component 2'])

print(principalDf.head(5))
print(df[['Label']].head())

finalDf = pd.concat([principalDf , df[['Label']]], axis = 1)
print(finalDf.head(1000))

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 =[ 1, 2]
colors = ['r', 'g', 'b']
for target, color in zip(targets, colors):
indicesToKeep = finalDf['Label'] == target
ax.scatter(finalDf.loc[indicesToKeep, 'principal component 1']
, finalDf.loc[indicesToKeep, 'principal component 2']
, c = color
, s= 50)

ax.legend(targets)
ax.grid()


print(pca.explained_variance_ratio_)


# General variance ratio >= 85%; here it is very much less(approx40) than that which
# indicates that so much of information is lost; so what I infer is that
# principal components chosen should be more than '2'




"""
Created on Sun Apr 5 08:04:06 2020

@author: mailm
"""

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import numpy as np
#from matplotlib import pyplot as plt # For plots only
data_array = np.loadtxt('data.txt', delimiter='\t', skiprows=1)

list_lab1 = [] # empty list for label 1
list_lab2 = [] # empty list for label 2



for i in range(999): # Random variable i
if( data_array[i, 0]==1):
list_lab1.append(data_array[i, 1:])
else:
list_lab2.append(data_array[i, 1:])

array_lab1 = np.array(list_lab1) # Required array of data of label 1
array_lab2 = np.array(list_lab2) # Required array of data of label 2


print(array_lab1)
print(array_lab2)
"""
#For the plots
for x in range(0,10): # For some random variable x and y
for y in range(x, 10):
if x != y :
plt.title('Feature {} vs {}'.format(x, y))
plt.scatter(array_lab1[:, x], array_lab1[:, y], color ='r', label='Label 1')
plt.scatter(array_lab2[:, x], array_lab2[:, y], color ='b', label='Label 2')
plt.xlabel('Feature {}'.format(x))
plt.ylabel('Feature {}'.format(y))
plt.legend()
plt.show()
"""



"""
Created on Sun Apr 2 01:05:21 2020

@author: mailm
"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature 1 vs 2 (Figure_1) is the best graph which differentiaites the two labels.
Loading