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
var Mongoose = require('mongoose') | |
var Hapi = require('hapi') | |
var Co = require('co') | |
Mongoose.connect('mongodb://localhost/mytestdb') | |
var userSchema = Mongoose.Schema({ | |
name: String | |
}) |
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
// What is a Tensor? | |
const myFirstTensor = tf.scalar(42) | |
console.log(myFirstTensor) | |
myFirstTensor.print() | |
const oneDimTensor = tf.tensor1d([1, 2, 3]) | |
oneDimTensor.print() |
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
data = OrderedDict( | |
amount_spent = [50, 10, 20, 5, 95, 70, 100, 200, 0], | |
send_discount = [0, 1, 1, 1, 0, 0, 0, 0, 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
df = pd.DataFrame.from_dict(data) |
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 sigmoid(z): | |
return 1 / (1 + np.exp(-z)) |
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 loss(h, y): | |
return (-y * np.log(h) - (1 - y) * np.log(1 - h)).mean() |
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
X = df['amount_spent'].astype('float').values | |
y = df['send_discount'].astype('float').values | |
def predict(x, w): | |
return sigmoid(x * w) | |
def print_result(y_hat, y): | |
print(f'loss: {np.round(loss(y_hat, y), 5)} predicted: {y_hat} actual: {y}') | |
y_hat = predict(x=X[0], w=.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
for w in np.arange(-1, 1, 0.1): | |
y_hat = predict(x=X[0], w=w) | |
print(loss(y_hat, y[0])) |
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 fit(X, y, n_iter=100000, lr=0.01): | |
W = np.zeros(X.shape[1]) | |
for i in range(n_iter): | |
z = np.dot(X, W) | |
h = sigmoid(z) | |
gradient = np.dot(X.T, (h - y)) / y.size | |
W -= lr * gradient | |
return W |
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 predict(X, W): | |
return sigmoid(np.dot(X, W)) |
OlderNewer