Skip to content

Instantly share code, notes, and snippets.

View vzhou842's full-sized avatar

Victor Zhou vzhou842

View GitHub Profile
@vzhou842
vzhou842 / train.py
Last active February 7, 2019 23:13
Training profanity-check
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.calibration import CalibratedClassifierCV
from sklearn.svm import LinearSVC
from sklearn.externals import joblib
# Read in data
data = pd.read_csv('clean_data.csv')
texts = data['text'].astype(str)
y = data['is_offensive']
(function() {
(function() {
console.log('Hello')
})()
(function() {
console.log('World!')
})()
})()
(function() {
(function() {
console.log('Hello')
})();
(function() {
console.log('World!')
})()
})()
const f1 = function() { console.log('Hello'); };
const f2 = function() { console.log('World!'); };
f1()(f2)();
const f1 = function() { console.log('Hello'); };
const f2 = function() { console.log('World!'); };
f1();(f2)();
const a = 'Hello'
const b = 'World' + '!'
[a, b].forEach(s => console.log(s))
@vzhou842
vzhou842 / neuron.py
Last active June 1, 2022 13:44
Neuron - An Introduction to Neural Networks
import numpy as np
def sigmoid(x):
# Our activation function: f(x) = 1 / (1 + e^(-x))
return 1 / (1 + np.exp(-x))
class Neuron:
def __init__(self, weights, bias):
self.weights = weights
self.bias = bias
@vzhou842
vzhou842 / network.py
Created March 5, 2019 17:56
Network - An Introduction to Neural Networks
import numpy as np
# ... code from previous section here
class OurNeuralNetwork:
'''
A neural network with:
- 2 inputs
- a hidden layer with 2 neurons (h1, h2)
- an output layer with 1 neuron (o1)
@vzhou842
vzhou842 / loss.py
Created March 5, 2019 18:01
Loss - An Introduction to Neural Networks
import numpy as np
def mse_loss(y_true, y_pred):
# y_true and y_pred are numpy arrays of the same length.
return ((y_true - y_pred) ** 2).mean()
y_true = np.array([1, 0, 0, 1])
y_pred = np.array([0, 0, 0, 0])
print(mse_loss(y_true, y_pred)) # 0.5
@vzhou842
vzhou842 / fullnetwork.py
Created March 5, 2019 18:16
Full Network - An Introduction to Neural Networks
import numpy as np
def sigmoid(x):
# Sigmoid activation function: f(x) = 1 / (1 + e^(-x))
return 1 / (1 + np.exp(-x))
def deriv_sigmoid(x):
# Derivative of sigmoid: f'(x) = f(x) * (1 - f(x))
fx = sigmoid(x)
return fx * (1 - fx)