Skip to content

Instantly share code, notes, and snippets.

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

Arseny Turin arseniyturin

🏠
Working from home
View GitHub Profile
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')
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'])
@arseniyturin
arseniyturin / binomial_distribution.py
Last active January 2, 2020 03:25
Binomial Distribution in Python
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)
@arseniyturin
arseniyturin / sgd.py
Last active February 2, 2020 16:09
Stochastic Gradient Descent
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):
@arseniyturin
arseniyturin / instagram_post_data.py
Last active February 5, 2023 16:16
How to retrieve instagram post data with Selenium
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():
@arseniyturin
arseniyturin / get_likes.py
Last active May 31, 2020 20:47
Get usernames who liked the post
# 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');''')
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))
@arseniyturin
arseniyturin / 8bit_to_16bit.js
Last active April 5, 2021 18:56
How to convert two 8bit number into 16bit in JavaScript
/*
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 '<<'
@arseniyturin
arseniyturin / sqlite_top_n.py
Last active June 12, 2021 17:25
SQLite: select top n products from each category
"""
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 │
@arseniyturin
arseniyturin / cookie_bayes.py
Created July 30, 2021 15:57
Naive Bayes Cookie Problem