Skip to content

Instantly share code, notes, and snippets.

View AparaV's full-sized avatar
🌴
On vacation

Apara Venkat AparaV

🌴
On vacation
View GitHub Profile
@AparaV
AparaV / sieve-eratosthenes-runtime-comparison.cpp
Last active April 8, 2017 00:51
Compare the runtime of the sieve against vectors and bool arrays
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
bool* boolPrimeSieveMemset(int64_t size) {
bool* prime = new bool[size + 1];
memset(prime, true, size + 1); //faster than loops and vectors
prime[0] = false;
import csv
import random
import numpy as np
import pandas as pd
def cleanup(df):
'''
Cleans data
1. Creates new features:
import tensorflow as tf
import numpy as np
def accuracy(prediction, labels):
return 0.5 * np.sqrt(((prediction - labels) ** 2).mean(axis=None))
train_size = np.shape(x_train)[0]
valid_size = np.shape(x_valid)[0]
test_size = np.shape(x_test)[0]
num_features = np.shape(x_train)[1]
import os
import csv
import numpy as np
import pandas as pd
import tensorflow as tf
train_size = np.shape(x_train)[0]
valid_size = np.shape(x_valid)[0]
test_size = np.shape(x_test)[0]
num_features = np.shape(x_train)[1]
def split(train_dataset):
'''
Shuffle data and split into 3 datasets
1. Training - 60%
2. Validation - 20%
3. Testing - 20%
'''
# Shuffle data
train_dataset = train_dataset.sample(frac=1)
@AparaV
AparaV / number-guessing-game.py
Last active January 8, 2018 21:28
Companion code for my Number Guessing Game article - https://aparav.github.io/2018/01/08/the-number-guessing-game/
'''
Author: Aparajithan Venkateswaran
Companion Article: https://aparav.github.io/2018/01/08/the-number-guessing-game/
'''
from scipy.special import comb
def conditional_prob(i, k, n, m):
'''
Calculates the probability of event C conditioned on Ri
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AparaV
AparaV / streamer.py
Last active July 22, 2021 16:22
Using the tweepy library to stream tweets has a catch. There is no built-in feature that allows you to stop streaming after a fixed time. To avoid manually terminating the stream, this code proposes a simple solution without any (complex) multi-threading.
import os
import time
import tweepy
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy import StreamListener
def authenticate():
library(geepack) # Run install.packages("geepack") if necessary
library(tidyr) # Run install.packages("tidyr") if necessary
### Generate synthetic data
### For demonstration purposes only.
### You do not need to understand how this section works.
### Please see line 43 for format of data frame and line 58 for fitting model.