Skip to content

Instantly share code, notes, and snippets.

View tanveer-sayyed's full-sized avatar

vernal-inertia tanveer-sayyed

  • Spherex
  • Mumbai
View GitHub Profile
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])
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).
@tanveer-sayyed
tanveer-sayyed / Fibonacci.py
Last active May 13, 2019 11:45
changed M to F
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)
@tanveer-sayyed
tanveer-sayyed / Eigen1.py
Last active May 13, 2019 08:15
updated A
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:
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))
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:
#!/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
@tanveer-sayyed
tanveer-sayyed / Soft Imputation on Iris Dataset.py
Last active July 24, 2019 09:44
added n_estimators= 100 in RandomForest
#!/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
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):
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):