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
model = Sequential() | |
model.add(Conv1D(filters=500, kernel_size=10, activation='relu', input_shape=(n_steps, n_features))) | |
model.add(MaxPooling1D(pool_size=10)) | |
model.add(Flatten()) | |
model.add(Dense(500, activation='relu')) | |
model.add(Dense(100, activation='relu')) | |
model.add(Dense(1, activation='sigmoid')) | |
model.compile(optimizer='adam', loss='mse') |
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
model = Sequential() | |
model.add(LSTM(100, activation='relu', return_sequences=True, input_shape=(n_steps, n_features))) | |
model.add(LSTM(50, activation='relu', return_sequences=False)) | |
model.add(Dense(10)) | |
model.add(Dense(1)) | |
model.compile(optimizer='adam', loss='mse', metrics=['mae']) |
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
from math import factorial as fac | |
def binomial_prob(n, x, p): | |
return round( ( fac(n) / ( fac(x) * fac(n-x) ) ) * (p**x) * (1-p)**(n-x) , 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
def SGD(X, y, lr=0.05, epoch=10, batch_size=1): | |
''' | |
Stochastic Gradient Descent for a single feature | |
''' | |
m, b = 0.5, 0.5 # initial parameters | |
log, mse = [], [] # lists to store learning process | |
for _ in range(epoch): |
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
from selenium import webdriver | |
driver = webdriver.Chrome('../chromedriver') | |
driver.get('https://www.instagram.com/accounts/login/') | |
def get_post_description(): | |
description = driver.execute_script('''return document.getElementsByClassName('C4VMK')[0].getElementsByTagName('span')[0].innerText''') | |
return description | |
def get_post_date(): |
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
# emulate click on a likes button | |
driver.execute_script('''document.getElementsByClassName('Nm9Fw')[0].lastElementChild.click()''') | |
# scroll down by 4000px to load more users who liked the post | |
driver.execute_script('''document.getElementsByClassName('Igw0E IwRSH eGOV_ vwCYk i0EQd')[0].firstChild.scrollBy(0, 4000);''') | |
time.sleep(0.2) | |
# collect usernames | |
usernames = driver.execute_script('''return document.getElementsByClassName('_7UhW9 xLCgt MMzan KV-D4 fDxYl');''') |
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
from numpy import log, dot, e | |
from numpy.random import rand | |
class LogisticRegression: | |
def sigmoid(self, z): return 1 / (1 + e**(-z)) | |
def cost_function(self, X, y, weights): | |
z = dot(X, weights) | |
predict_1 = y * log(self.sigmoid(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
/* | |
Problem: | |
You have 16 bit number, for example 12345. | |
In hexadecimal it looks like this: 0x3039, | |
but in the buffer it will look like this: <Buffer: 39 30> | |
How to convert two 8 bit numbers back to 16 bit number? | |
Bitwise operator '<<' |
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
""" | |
Table 'Products' contains different products, their categories and prices. | |
We want to select top n products per each category rated by their price | |
SOLUTION: Window function RANK() | |
1. TABLE 'Products' | |
┌───────────┬────────────┬───────┐ | |
│ product │ category │ price │ | |
├───────────┼────────────┼───────┤ | |
│ product_A │ category_A │ 55 │ |
OlderNewer