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.seed(33) | |
x = runif(100, min=0, max=1) | |
outlier_values = c(1e2, 1e3, 1e4, 1e5, 1e6) | |
for (i in outlier_values) { | |
x[100] = i | |
y = (x - mean(x)) / (sd(x)) | |
print(y[100]) | |
} |
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
import numpy as np | |
n = 1 # number of observations | |
k = 5 # number of categories | |
c = 1 # 2da categoria | |
dim = 3 # dimension of embeddings | |
E = np.random.rand(k, dim) # embedding matrix | |
x_onehot = np.full((k, n), 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
import numpy as np | |
import torch | |
import torch.nn.functional as F | |
torch.manual_seed(99) | |
# 5 features, 3 clases, 1 ejemplo | |
X = torch.randn(5) | |
W1 = torch.randn(3,5) | |
W2 = W1.detach().clone() # una matriz de perdida por loss function |
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
z_scale = function(x) (x - mean(x)) / (sd(x)) | |
rob_scale = function(x) (x - median(x)) / (IQR(x)) | |
set.seed(12) | |
x = runif(10) | |
y = x | |
y[10] = 10 # datos con outlier | |
# sin outlier | |
x_zscale = z_scale(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
import numpy as np | |
A = np.arange(12).reshape(4,3) | |
# opcion 1 | |
res1 = np.apply_over_axes(np.cumsum, A, axes=[0,1]) | |
# opcion 2 | |
res2 = A.cumsum(0).cumsum(1) | |
# opcion 3 | |
res3 = np.cumsum( np.cumsum(A, axis=0), axis=1) |
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
import numpy as np | |
A = np.array([1,2,35,8]) | |
n = 2 | |
# idx of top n values (NOT SORTED) | |
idx_top = np.argpartition(A, -n)[-n:] | |
# sort idx from largest value to lowest | |
idx_top = idx_top[np.argsort(-A[idx_top])] | |
values_top = A[idx_top] |
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
# simulate highly correlated x1-x2 | |
set.seed(8) | |
X = MASS::mvrnorm( | |
n = 100 | |
, mu = c(0, 0) | |
, Sigma = matrix(c(1, 0.99, 0.99, 1), nrow=2, byrow=T) | |
, empirical = F | |
) | |
# simulate y | |
df = data.frame( |
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
import numpy as np | |
import scipy.stats as stats | |
arr = np.array([0,2,3,0,236,8]) | |
arr_ranks1 = np.searchsorted(np.sort(arr), arr) | |
arr_ranks2 = stats.rankdata(arr, "average") | |
arr_ranks3 = stats.rankdata(arr, "average") / len(arr) |
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
# when using yield in a function, you are creating a generator object | |
def cuadrado(): | |
for i in range(10): | |
yield i**2 | |
for num in cuadrado(): | |
print(num) |