This file contains 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
# Exact generator | |
exactMatrix = ExactMatrix(exactGenerator) | |
# Show matrix | |
plotMatrix(exactMatrix, 'Exact transition matrix', 'Percent') |
This file contains 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
# Define exact transition matrix | |
def ExactMatrix(exactQ): | |
# Define identity matrix | |
I = pd.DataFrame( | |
np.identity(exactQ.shape[0]), | |
index = exactQ.index, | |
columns = exactQ.columns | |
) | |
# Exact transition matrix | |
exactMatrix = None |
This file contains 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
# Exact generator | |
exactGenerator = ExactGenerator(generatorMatrix) | |
# Show matrix | |
plotMatrix(exactGenerator, 'Exact generator') |
This file contains 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
# Define exact generator function | |
def ExactGenerator(Q): | |
# Define Gi and Bi | |
# Gi | |
GiMatrix = Q.copy() | |
for i in range(Q.shape[1]): | |
for j in range(Q.shape[0]): | |
if i == j: #Diagonal matrix | |
GiMatrix.iloc[i, j] = abs(GiMatrix.iloc[i, j]) | |
else: #Non-Diagonal matrix |
This file contains 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
# Generator matrix | |
generatorMatrix = GeneratorMatrix(matrix) | |
# Show matrix | |
plotMatrix(generatorMatrix, 'Generator matrix') |
This file contains 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
# Define generator matrix function | |
def GeneratorMatrix(P): | |
# Define identity matrix | |
I = pd.DataFrame( | |
np.identity(P.shape[0]), | |
index = P.index, | |
columns = P.columns | |
) | |
# Generator matrix | |
generatedMatrix = None |
This file contains 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
# Set auto reload | |
%reload_ext autoreload | |
%autoreload 2 | |
# Import libraries | |
import warnings | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns |
This file contains 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
# Export | |
pd.concat( | |
[ | |
pd.DataFrame(X, columns = ['X1']), | |
pd.DataFrame(y, columns = ['y']) | |
], | |
axis = 1 | |
).to_csv( | |
'Theil-Sen_Data.csv', | |
index = 0 |
This file contains 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
# Compare | |
plt.figure(figsize = (10, 6)) | |
plt.scatter( | |
X, | |
y, | |
c = 'teal' | |
) | |
plt.plot( | |
X, | |
OLS.predict(X), |
This file contains 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
# Theil-Sen | |
TS = TheilSenRegressor() | |
TS.fit(X, y.ravel()) | |
# Plot | |
plt.figure(figsize = (10, 6)) | |
plt.scatter( | |
X, | |
y, | |
c = 'teal' |
NewerOlder