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 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'] |
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
(function() { | |
(function() { | |
console.log('Hello') | |
})() | |
(function() { | |
console.log('World!') | |
})() | |
})() |
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
(function() { | |
(function() { | |
console.log('Hello') | |
})(); | |
(function() { | |
console.log('World!') | |
})() | |
})() |
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
const f1 = function() { console.log('Hello'); }; | |
const f2 = function() { console.log('World!'); }; | |
f1()(f2)(); |
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
const f1 = function() { console.log('Hello'); }; | |
const f2 = function() { console.log('World!'); }; | |
f1();(f2)(); |
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
const a = 'Hello' | |
const b = 'World' + '!' | |
[a, b].forEach(s => console.log(s)) |
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 | |
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 |
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 | |
# ... 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) |
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 | |
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 |
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 | |
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) |
OlderNewer