Skip to content

Instantly share code, notes, and snippets.

View ra312's full-sized avatar
🎯
Focusing

ra312 ra312

🎯
Focusing
View GitHub Profile
@ra312
ra312 / s4di_ch01_exercises.sc
Created June 18, 2019 09:13 — forked from parambirs/s4di_ch01_exercises.sc
Solutions for "Scala for the Impatient", chapter 1 exercises
package src.exercises
import scala.math._
import BigInt.probablePrime
import util.Random
object chap01 {
// 1. In the Scala REPL, type 3. followed by the Tab key. What methods can be
// applied?
// => Do it in REPL. There are many methods including %, &, *, +, toByte, toChar etc.
from azureml.core import Workspace, Environment
from azureml.core.conda_dependencies import CondaDependencies
from azureml.core import Image
ws = Workspace.from_config()
env = Environment(name = 'myenv')
conda_dep = CondaDependencies()
# Installs numpy version 1.17.0 conda package
conda_deps = ['blas=1.0',
@ra312
ra312 / test_hyperopt_sampling.py
Last active April 26, 2020 13:30
hyperopt:generate mixed samples
from hyperopt import hp
from hyperopt.pyll.stochastic import sample
space = hp.choice('label', [
hp.uniform('sub_label_1', 0.3, 0.8),
hp.normal('sub_label_2', 0.5, 1.0), None, 0, 1, "anything"
])
space = {
# None by default
'max_depth': hp.choice('max_depth', [None, np.arange(1, 300, 1,dtype=int)]),
# 2 by default
CREATE TABLE accounts(
JE_ID serial PRIMARY KEY,
ACCOUNT_DR integer NOT NULL,
ACCOUNT_CR integer NOT NULL,
SUMM integer NOT NULL,
REVERSED integer NOT NULL,
USER_ID integer NOT NULL,
DATA integer NOT NULL,
DATE_DOC integer NOT NULL,
APPROVER_ID varchar(256) NOT NULL,
@ra312
ra312 / fetch_chrome_history.py
Last active May 21, 2020 15:32
raise my browsing self-awareness
import os
import sqlite3
import operator
from collections import OrderedDict
#path to user's history database (Chrome)
data_path = os.path.expanduser('~')+"/Library/Application Support/Google/Chrome/Default"
files = os.listdir(data_path)
history_db = os.path.join(data_path, 'history')
#querying the db
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
@ra312
ra312 / marketing_costs.py
Created June 6, 2020 10:17
correctly solves example case, but linear codependency failed
import numpy as np
from sklearn import linear_model
def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold):
"""
:param marketing_expenditure: (list) A list of integers with the expenditure for each previous campaign.
:param units_sold: (list) A list of integers with the number of units sold for each previous campaign.
:param desired_units_sold: (integer) Target number of units to sell in the new campaign.
:returns: (float) Required amount of money to be invested.
"""
@ra312
ra312 / bitwise_pairs.py
Created June 6, 2020 14:15
counting pairs with bitwise product
import itertools
def countPairs(arr):
# Write your code here
count = 0
for i, j in itertools.combinations(arr, 2):
v = i & j
if v != 0 :
if (v % 2 == 0) | (v == 1):
count+=1
return count
# This is an application transferring csv data into database
# We choose a NoSQL database MongoDB since we have to store data and the logs of data GET requests# We prefer to choose PostgreSQL rather than MySQL(purely relation) or SQLite (no concurrency support)
import json
import csv
import pandas as pd
import os
from pymongo import MongoClient
cwd = os.path.dirname(__file__)
csvpath=os.path.join(cwd,'task_data.csv')
@ra312
ra312 / label_prop_plot_roc_auc_score.py
Created July 31, 2020 06:25
label_prop_plot_roc_auc_score
import matplotlib.pyplot as plt
def label_prop_test(model, kernel, params_list, X_train, X_test, y_train, y_test):
plt.figure(figsize=(20,10))
n, g = 0, 0
roc_scores = []
if kernel == 'rbf':
for g in params_list:
lp = model(kernel=kernel, n_neighbors=n, gamma=g, max_iter=100000, tol=0.0001)
lp.fit(X_train, y_train)
roc_scores.append(roc_auc_score(y_test, lp.predict_proba(X_test), multi_class='ovo'))