2020年7月18日 星期六

背景執行 gunicorn

安裝
sudo pip install gunicorn

背景執行
sudo gunicorn -w 1 -b 0.0.0.0:80 run:app --daemon

結束
查PID
ps -ef | grep gunicorn

sudo kill -9 12705




2020年7月16日 星期四

2020年7月2日 星期四

資料前處理

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
df["population_density"] = scaler.fit_transform(df["population_density"].values.reshape(-1, 1))

2020年6月20日 星期六

python df heatmap

heatmap = df[["city","class"]]
heatmap["cnt"] = 1
heatmap = heatmap.groupby(["city","class"]).sum().unstack().fillna(0)

2020年6月19日 星期五

sigmoid

def sigmoid(X):  # define activation: sigmoid
    output = 1 / (1 + np.exp(-X))
    return output

def sigmoid_gradient(X):
    output = sigmoid(X)*(1-sigmoid(X))
    return output

def softmax(X):  # define activation: softmax
    return np.exp(X) / np.sum(np.exp(X), axis=1, keepdims=True)

def cross_entropy(p, q):
    epsilon = 1e-15
    H = 0
    for i in range(len(p)):
        H += -p[i]*np.log(q[i]+epsilon)

    H = H.sum()/p.shape[0]
    return H


from tensorflow import keras
# 做 One-hot encoding
y = keras.utils.to_categorical(array)

2020年6月18日 星期四

SQL (MySQL)

查詢table更新時間
select UPDATE_TIME FROM information_schema.TABLES where TABLE_NAME='{}'

SHOW VARIABLES LIKE '%group_concat%';

SET GLOBAL group_concat_max_len=102400;
SET SESSION group_concat_max_len=102400;


ON DUPLICATE KEY UPDATE

ALTER TABLE Persons ADD UNIQUE (Id_P) 

GROUP_CONCAT()

update update_test A inner join (select PAY_DATE,sum(EXPENSE) as U1,max(EXPENSE) as U2 from expense where PAY_DATE >= '2020/4/1' group by PAY_DATE) B on A.PAY_DATE=B.PAY_DATE set A.SUM_PAY=B.U1,A.MAX_PAY=B.U2;

數字轉字串
CONVERT(1,CHAR)

修改表格名
ALTER TABLE `原表格名` RENAME TO `新表格名`

改欄位名稱
ALTER TABLE `表格名` CHANGE COLUMN `舊欄位名` `新欄位名` 欄位類型
ALTER TABLE mfg_skill CHANGE COLUMN STAGE DEPT varchar(6)



2020年6月11日 星期四

GitLab

Git global setup
git config --global user.name "智銘 吳"
git config --global user.email "wugimy@gmail.com"
Create a new repository
git clone https://gitlab.aiacademy.tw/at091013/my-first-project.git
cd my-first-project
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.aiacademy.tw/at091013/my-first-project.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.aiacademy.tw/at091013/my-first-project.git
git push -u origin --all
git push -u origin --tags