This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
from numpy import array | |
from sklearn.decomposition import PCA | |
D = array([[1, 1],[2, 2],[3, 3],[4, 4],[5, 5], # Matrix D has all the | |
[6, 6],[7, 7],[8, 8],[9, 9]]) # points on line x = y | |
# Adding noise: | |
E = np.zeros(np.shape(D)) | |
E = D + np.random.rand(np.shape(D)[0], np.shape(D)[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = np.array([[1, 4], [2, 3]]) | |
lambdas, eigenVectors = np.linalg.eig(A) | |
eigenVectors = Scaling_Eigen_Vectors(eigenVectors= eigenVectors) | |
print('lambdas: \n', lambdas) | |
Λ = np.around(np.linalg.inv(eigenVectors).dot(A).dot(eigenVectors), | |
decimals= 8) | |
print('diagonalized lambdas (Λ): \n', Λ) | |
# power of matrix = 20 | |
print('With factorization: \n', eigenVectors.dot(Λ**20).dot(np.linalg.inv(eigenVectors))) | |
print('Without factorization: \n', M .dot(M).dot(M).dot(M).dot(M).dot(M). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
F = np.array([[1,1],[1,0]]) | |
print('F^1: \n', F) | |
print('F^2: \n', F.dot(F)) | |
print('F^3: \n', F.dot(F).dot(F)) | |
print('F^4: \n', F.dot(F).dot(F).dot(F)) | |
print('F^5: \n', F.dot(F).dot(F).dot(F).dot(F)) | |
lambdas, eigenVectors = np.linalg.eig(F) | |
eigenVectors = Scaling_Eigen_Vectors(eigenVectors= eigenVectors) | |
print('lambdas of F^1: \n', lambdas) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = np.array([[1, 4], [2, 3]]) | |
print('A: \n', A) | |
lambdas, eigenVectors = np.linalg.eig(A) | |
eigenVectors = Scaling_Eigen_Vectors(eigenVectors= eigenVectors) | |
print('lambdas: \n', lambdas) | |
print('eigenvectors: \n', eigenVectors) | |
Plot_All(A, eigenVectors) | |
Output: | |
A: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Plot_All(A, eigenvectors): | |
plt.figure(figsize=(12,3)) | |
plt.subplot(1,3,1) | |
V = [np.array([[0, 0]]), [eigenVectors]] # padded [0,0] just to get the pink colour | |
for i in range(len(V)): | |
for j in range(len(V[i])): | |
plt.quiver(*([0],[0]), V[i][j][0], V[i][j][1], angles='xy', scale_units='xy', scale=1, color=plt.cm.Paired((i+3)/10.)) | |
plt.grid(b=True, which='major', linestyle= ':') | |
plt.xticks(np.arange(-5, 5 + 1, 1)) | |
plt.yticks(np.arange(-5, 5 + 1, 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q = np.array([[0, -1], [1, 0]]) # All REAL numbers | |
print('Asymmetry check: \n', Q == -np.transpose(Q) ) | |
lambdas, eigenVectors = np.linalg.eig(Q) | |
eigenVectors = Scaling_Eigen_Vectors(eigenVectors= eigenVectors) | |
print('lambdas: \n', lambdas) | |
print('eigenvectors: \n', eigenVectors) | |
Output: | |
Asymmetry check: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
@author: tanveer | |
""" | |
import pandas as pd | |
import numpy as np | |
import random | |
from sklearn.datasets import load_iris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
@author: tanveer | |
""" | |
"""On Spyder editor hit F5. On jupyter-notebook paste in a single cell and press ctrl+Enter. Run atleast 15 times.""" | |
threshold = 0.70 # TRY thresholds -> {0.72, 0.73, 0.74, 0.75} | |
import time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valueCounts = {} | |
def CountAll(): | |
global all_columns, nanCounts, valueCounts | |
all_columns = list(df) | |
nanCounts = df.isnull().sum() | |
for x in all_columns: | |
valueCounts[x] = df[x].value_counts() | |
"""Random but proportional replacement(RBPR) of numeric""" | |
def Fill_NaNs_Numeric(col): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valueCounts = {} | |
def CountAll(): | |
global all_columns, nanCounts, valueCounts | |
all_columns = list(df) | |
nanCounts = df.isnull().sum() | |
for x in all_columns: | |
valueCounts[x] = df[x].value_counts() | |
"""-------------------------------------------------------------------------""" | |
def Fill_NaNs_Catigorical(col): |
NewerOlder