Skip to content

Instantly share code, notes, and snippets.

View Blaizzy's full-sized avatar
🏠
Working from home

Prince Canuma Blaizzy

🏠
Working from home
View GitHub Profile
@Blaizzy
Blaizzy / .py
Last active February 3, 2019 09:49
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),'%')
@Blaizzy
Blaizzy / load.py
Last active February 13, 2019 23:27
from keras.datasets import mnist
(train_images, train_labels),(test_images, test_labels) = mnist.load_data()
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'))
nn.compile(optimizer = 'rmsprop',
loss= 'categorical_crossentropy',
metrics = ['accuracy'])
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)
model.fit(training_images, train_labels, epochs = 8, batch_size = 64)
test_loss, test_acc = model.evaluate(training_images, train_labels)
print('Test accuracy', test_acc)
# 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
@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.
# 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