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
| from sklearn.linear_model import LogisticRegression | |
| #Creating a classifier | |
| clf = LogisticRegression() | |
| # Traning a testing Accuracy | |
| model = clf.fit(X_train, y_train.values.ravel()) | |
| acc = clf.score(X_train, y_train.values.ravel()) | |
| print('Model Accuracy: ', round(acc*100,3),'%') |
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
| from keras.datasets import mnist | |
| (train_images, train_labels),(test_images, test_labels) = mnist.load_data() |
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
| from keras import models | |
| from keras import layers | |
| nn = models.Sequential() | |
| nn.add(Dense(512, activation = 'relu', input_shape = (28*28,))) | |
| nn.add(Dense(256, activation = 'relu')) | |
| nn.add(Dense(10, activation = 'softmax')) |
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
| nn.compile(optimizer = 'rmsprop', | |
| loss= 'categorical_crossentropy', | |
| metrics = ['accuracy']) |
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
| train_images = train_images.reshape((60000,28*28)) | |
| train_images = train_images.astype('float32')/255 | |
| test_images = test_images.reshape((10000,28*28)) | |
| test_images = test_images.astype('floa32t')/255 | |
| from keras.utils import to_categorical | |
| train_images = to_categorical(train_images) | |
| test_images = to_categorical(test_images) |
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
| model.fit(training_images, train_labels, epochs = 8, batch_size = 64) |
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
| test_loss, test_acc = model.evaluate(training_images, train_labels) | |
| print('Test accuracy', test_acc) |
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
| # First you might want to install & import tf 2.0 | |
| !pip install -q tensorflow==2.0.0-alpha0 | |
| import tensorflow as tf | |
| # Let's implement a simple Linear layer (mx+b) using tf.function | |
| @tf.function | |
| def add(a,b): | |
| return a + b | |
| @tf.function |
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
| @tf.function | |
| def f(x): | |
| for i in range(10): # Static python loop, we'll not convert it | |
| do_stuff() | |
| for i in tf.range(10): # depends on a tensor, we'll convert it | |
| # function call | |
| f(10) | |
| # If you're curious you can inspect the code autograph generates. |
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
| # Imports | |
| import torch | |
| from skimage import io, transform | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from torch.utils.data import Dataset, DataLoader | |
| from torchvision import transforms, utils | |
| from pathlib import Path | |
| # Dataset Subclassing |
OlderNewer