Skip to content

Instantly share code, notes, and snippets.

View saivarunk's full-sized avatar
💭
drowned into k8s

Varun Kruthiventi saivarunk

💭
drowned into k8s
View GitHub Profile
@saivarunk
saivarunk / h20_automl.r
Created December 30, 2018 19:55
Exploring H2O.ai AutoML
library(data.table)
library(h2o)
# Load train and properties data
properties <- fread("../input/properties_2016.csv", header=TRUE, stringsAsFactors=FALSE, colClasses = list(character = 50))
train <- fread("../input/train_2016_v2.csv")
training <- merge(properties, train, by="parcelid",all.y=TRUE)
# Initialise h20
def build_bidirectional_model(X, y):
# define model
model = Sequential()
model.add(Bidirectional(LSTM(50, activation='relu'), input_shape=(n_steps, n_features)))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=200, verbose=0)
return model
def split_sequence(sequence, n_steps):
X, y = list(), list()
for i in range(len(sequence)):
end_ix = i + n_steps
if end_ix > len(sequence)-1:
break
seq_x, seq_y = sequence[i:end_ix], sequence[end_ix]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
# read bitcoin pricing data
bitcoin_data = pd.read_csv('input/bitstampUSD_1-min_data_2012-01-01_to_2018-11-11.csv')
# parse date using pandas
bitcoin_data['date'] = pd.to_datetime(bitcoin_data['Timestamp'],unit='s').dt.date
# group by date and pick 'Weighted_Price'
grouped_data = bitcoin_data.groupby('date')
real_price = grouped_data['Weighted_Price'].mean()
# choose a number of time steps
n_steps = 5
# split into sequence
X, y = split_sequence(real_price.values, n_steps)
# reshape from [samples, timesteps] into [samples, timesteps, features] to fit in LSTM model
n_features = 1
X = X.reshape((X.shape[0], X.shape[1], n_features))
# train model
bidirectional_model = build_bidirectional_model(X, y)
# predict using the test data
yhat = bidirectional_model.predict(X_test, verbose=0)
trace_high = go.Scatter(
x=test_dates,
y=y_test,
name = "Original",
line = dict(color = '#17BECF'),
opacity = 0.8)
trace_low = go.Scatter(
x=test_dates,
y=pd.DataFrame(yhat)[0].values,
@saivarunk
saivarunk / docker-1.sh
Created August 11, 2021 07:34
Docker Setup - 1
sudo apt-get remove docker docker-engine docker.io containerd runc # Remove any traces of older Docker installation
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
@saivarunk
saivarunk / docker-2.sh
Last active August 11, 2021 07:42
Installing Docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world # Command to verify Docker is installed.
## Adding your user to Docker group - Recommended Step
sudo groupadd docker
sudo usermod -aG docker $USER