Skip to content

Instantly share code, notes, and snippets.

View sentiment-analysis.py
import torch
import pandas as pd
import logging
import os
from dotenv import load_dotenv
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from datetime import datetime
@harrywang
harrywang / ask_iching.py
Created Jun 12, 2022
This program uses three-coin approach to consult the IChing and returns the hexagram (see https://harrywang.me/iching for more details)
View ask_iching.py
def consult_oracle():
import random
hex = ''
for i in range(6): # toss 6 times to get the hex
toss = 0
line = 0
for i in range(3): # each toss with three coins to generate one line
View ensemble-learning-hints.py
# partial code snippets shown as hints
# voting regressor
from sklearn.ensemble import VotingRegressor
voting_reg = VotingRegressor(
estimators = [
('lin', lin_reg_pipeline),
('svm', svm_reg_pipeline),
('sgd', sgd_reg_pipeline),
View sgd-grid-search-example.py
# sgd regression pipeline with grid search
from sklearn.linear_model import SGDRegressor
from sklearn.model_selection import GridSearchCV
param_grid = [
{
'sgd_reg__max_iter':[100000, 1000000], # if number is too small, you will get a warning
'sgd_reg__tol':[1e-10, 1e-3],
'sgd_reg__eta0':[0.001, 0.01]
}
@harrywang
harrywang / feature-type-based-selection.py
Last active May 4, 2021
code snippet to show how to select features based on type: numerical vs. categorical
View feature-type-based-selection.py
# example to show how to select features based on type: numerical vs. categorical
import pandas as pd
# load the data
df = pd.read_csv("housing.csv")
# find numerical features and categorical features based on the type of feature
df_num = df.select_dtypes(exclude ='object')
df_cat = df.select_dtypes(include ='object')
# select numerical features and categorical features
View config.md

Setup

Use V3 from Tai: Screen Shot 2020-06-10 at 9 58 22 AM

python -m venv venv
source venv/bin/activate
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple/
@harrywang
harrywang / lin_reg_full_pipeline.py
Created Apr 22, 2020
Linear Regression Full Pipeline Code Snippet
View lin_reg_full_pipeline.py
### code snippet ####
from sklearn.linear_model import LinearRegression
lin_reg_full_pipeline = Pipeline(
steps=[
('preprocessor', preprocessor),
('lin_reg', LinearRegression()),
]
)
@harrywang
harrywang / object-detection.json
Created Mar 14, 2020
google object detection result
View object-detection.json
{
"responses": [
{
"localizedObjectAnnotations": [
{
"mid": "/j/5qg9b8",
"name": "Packaged goods",
"score": 0.8396697,
"boundingPoly": {
"normalizedVertices": [
@harrywang
harrywang / ocr.json
Created Mar 14, 2020
google ocr result
View ocr.json
{
"responses": [
{
"textAnnotations": [
{
"locale": "it",
"description": "Unilever\nDove Dove\n国潮盛富 全民嗨购,\nDe Dove Dove ve\nम\n满88送88礼包\n",
"boundingPoly": {
"vertices": [
{
@harrywang
harrywang / index.html
Created Mar 6, 2020 — forked from d3noob/index.html
Interactive tree v4 external json
View index.html
<!DOCTYPE html>
<meta charset="UTF-8">
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 3px;
}