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
def encode_onehot(labels: list): | |
labels = np.array(labels) | |
shape = (labels.size, labels.max()+1) | |
one_hot = np.zeros(shape) | |
rows = np.arange(labels.size) | |
one_hot[rows, labels] = 1 | |
return one_hot |
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
from IPython.display import FileLink | |
FileLink(PATH) |
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
def show_img_grid(images, labels, N): | |
n = int(N**(0.5)) | |
k = 0 | |
f, axarr = plt.subplots(n,n,figsize=(10,10)) | |
for i in range(n): | |
for j in range(n): | |
axarr[i,j].set_title(labels[k]) | |
axarr[i,j].imshow(images[k]) | |
k += 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
def count_parameters(model): | |
return sum(p.numel() for p in model.parameters() if p.requires_grad) |
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
ABCDEFGHIJKLMNOPQRSTUVWXYZfabcdefghijklmnopqrstuvwxyz |
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
fig = plt.figure(figsize=(4,4)) | |
ax = fig.add_subplot(111, projection='3d') | |
ax.scatter(df['Gene 1'], df['Gene 2'], df['Gene 3']) |
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
fig, axs = plt.subplots(1, 2) | |
fig.set_figheight(4) | |
fig.set_figwidth(13) | |
axs[0].scatter(X1, Y1) | |
axs[1].scatter(X2, Y2) | |
axs[0].set_title("North") | |
axs[0].set_ylabel('mortality') | |
axs[0].set_xlabel('hardness') |
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
seed = 42 | |
torch.manual_seed(seed) | |
torch.cuda.manual_seed(seed) | |
np.random.seed(seed) | |
random.seed(seed) |
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
class DataLoader: | |
def __init__(self, dir): | |
self.dir = dir | |
self.filenames = [filename for filename in os.listdir(dir)] | |
self.index = -1 | |
self.size = len(self.filenames) | |
def __iter__(self): | |
return self |