Skip to content

Instantly share code, notes, and snippets.

View andrewwxy's full-sized avatar

Andrew andrewwxy

View GitHub Profile
@BastiTee
BastiTee / README.md
Last active June 8, 2022 07:50
Bundesliga Volatility Kata

This code is now available at Kaggle.

# Specify the stock that you want to analyze.
stock = 'TSLA'
# Request for data from Finhub.io (30 calls per second limit: https://finnhub.io/docs/api/rate-limit).
r = requests.get('https://finnhub.io/api/v1/stock/insider-transactions?symbol='+stock+'&token=YOUR API KEY')
# Load the JSON file as a string.
test = json.loads(r.text)
@samarth-agrawal-86
samarth-agrawal-86 / sklearn_train_test_split_random.py
Last active July 20, 2023 06:39
Random Split - To create train valid test dataset using sklearn train test split
import pandas as pd
df = pd.read_csv('/kaggle/input/bluebook-for-bulldozers/TrainAndValid.csv', parse_dates=['saledate'], low_memory=False)
from sklearn.model_selection import train_test_split
# Let's say we want to split the data in 80:10:10 for train:valid:test dataset
train_size=0.8
X = df.drop(columns = ['SalePrice']).copy()
import numpy as np
import PIL
from io import BytesIO
import matplotlib.pyplot as plt
def plt_to_text(plt_fig=None,width=144,vscale=0.96,colorful=True,invert=False,crop=False,outfile=None):
"""Displays matplotlib figure in terminal as text. You should use a monospcae font like `Cascadia Code PL` to display image correctly. Use before plt.show().
- **Parameters**
- plt_fig: Matplotlib's figure instance. Auto picks if not given.
- width : Character width in terminal, default is 144. Decrease font size when width increased.
@betterdatascience
betterdatascience / missforest.py
Created November 4, 2020 11:34
004_missforest
# Add imputed values as columns to the untouched dataset
iris_orig['MF_sepal_length'] = X_imputed[:, 0]
iris_orig['MF_petal_width'] = X_imputed[:, -1]
comparison_df = iris_orig[['sepal_length', 'MF_sepal_length', 'petal_width', 'MF_petal_width']]
# Calculate absolute errors
comparison_df['ABS_ERROR_sepal_length'] = np.abs(compaison_df['sepal_length'] - comparison_df['MF_sepal_length'])
comparison_df['ABS_ERROR_petal_width'] = np.abs(compaison_df['petal_width'] - comparison_df['MF_petal_width'])
# Show only rows where imputation was performed
votes scaled_prob
64.02877697841728 0
79.85611510791367 0
93.52517985611513 0
107.19006190396522 0.0
120.14388489208633 0
135.97122302158274 0
151.07913669064752 0
159.70386481512466 0.011627906976744207
173.36038146227202 0.02906976744186074
import pandas as pd
from pandas_datareader import data, wb
import datetime
start = pd.to_datetime('2020-02-04')
end = pd.to_datetime('today')
tesla_df = data.DataReader('TSLA', 'yahoo', start , end)
tesla_df
@qdm12
qdm12 / README.md
Last active May 7, 2024 14:08
Wireguard and iptables restrictions for multiple users

Wireguard and iptables restrictions for multiple users

If you don't know what Wireguard is, well, you should. It's fast, easy to setup and highly configurable. We will configure Wireguard for multiple users with various restrictions using iptables.

Assumptions

This should fit most setups (not mine though 😉)

@felixlohmeier
felixlohmeier / bash-refine.md
Last active April 12, 2022 05:27
How to control OpenRefine 3.3+ with cURL (and jq) in Bash scripts

How to control OpenRefine 3.3+ with cURL (and jq) in Bash scripts

tested on Fedora 32 with bash 5.0.17 and curl 7.69.1

Quick start

  1. Clone this gist
git clone https://gist.github.com/d76bd27fbc4b8ab6d683822cdf61f81d.git bash-refine
PROJECT='ai-analytics-solutions'
BUCKET='ai-analytics-solutions-kfpdemo'
REGION='us-central1'
from datetime import datetime
import apache_beam as beam
def parse_nlp_result(response):
return [
# response, # entire string