# 南一中人工智慧營
- [網站整理](https://moodle.tnfsh.tn.edu.tw/course/view.php?id=27#section-17)
:::spoiler <font color="bule">目錄</font>
[TOC]
:::
## M1 AI簡介
- 自駕車
- 雲端運算+邊緣運算
- 小遊戲
- [拼字](https://research.google.com/semantris) -> **NLP**
- [繪圖](https://quickdraw.withgoogle.com/)
- [猜拳](https://www.afiniti.com/corporate/rock-paper-scissors)
- [系統圖(loopy)](https://ncase.me/loopy)
- 正/負相關、流程
- 聯合國 SDGs
- [17個永續目標](https://sdgs.un.org/goals)
- ethics in AI (AI倫理)
## M2 統計數據
- AI>ML>DL(大圈圈到小圈圈)
**1.problem scoping (問題界定)**
- 4W/利益相關者/關係/時間
**2.data acquisition (資料收集)**
**3.data exploration (資料探索)**
- [可視化圖形(統計圖表)](https://datavizcatalogue.com/)
- [opendata(政府資料開放平台)](https://data.gov.tw/)
**4.modeling**
**5.evaluation (模型評估)**
- accuracy=TP/(TP+FN)
- recall=TP/(TP+FN)
| Column 1 | 實際為真 | 實際為 |
| -------- | -------- | -------- |
| Text | Text | Text |
**deployment (部署)**
## M3 NLP
[文風機器人](https://quillbot.com/)
### data process
text -> number
**1.sentence segmentantion**
- 分段
**2.tokenization**
- 斷詞
- stopword,number...
**3.stemming(詞幹)**
- ex:creating -> creat
**4.lemmatization**
- ex:creating -> create
the bag of words representation(詞袋)
- 文字轉向量
- 向量矩陣
1.?
2.?
3.create document vectors
4.
>vector=magmitude(大小)+directiom(方向)
[詞向量](http://ronxin.github.io/wevi/)
兩向量夾角越小,之間相關性越大
## M4
[影像訓練](https://teachablemachine.withgoogle.com/train)
pixel(向素)
## MNIST資料集
- MNIST資料集:0~9手寫資料集(60000 train data + 10000 valid data)
- One Hot encoding(分類/機率)
- Multiple Layer Perceptron Neural Network(MLP)多層感知器
- CNN
**1.資料集準備:**
- Load Dataset
- Split Dataset (train:valid:test=0.64:0.16:0.2) ``(8(->8:2):2)``
**2.設計分類模型:**
- Input Layer
- Convolution Layer + Pooling Layer(卷積+池化)
- Flatten Layer(攤平)
- Dense Layer
- Output Layer
**3.訓練參數的設定:**
- Loss function
- Optimizer(調動參數的策略)
- Evaluation Metrics(模型優劣的標準)
- accuracy=TP/(TP+FN)
**4.訓練模型:**
- Epochs(訓練次數)
- :-1: STG(隨機梯度)(下降較慢/不易收斂)
- :+1: Batch size(分梯次) ==依梯次誤差值修正==
**5.訓練驗證:**
- Evaluate
### 實作
[mnist](https://colab.research.google.com/drive/1jL4j2P3hlFFitKrGWUUeu0LF0pz6t0FA?usp=sharing)
- import
```python=
from tensorflow import keras #從下層呼叫上層(物件導向)
from tensorflow.keras import layers
```
- 正規化(Normalization)
- "float32"轉浮點數
- mnist資料集導入
```python=
(x_train,y_train),(x_test,y_test)=keras.datasets.mnist.load_data()
#已分割60000 train & 10000 test
```
- np.expand_dims(,)
```python=
x_train=np.expand_dims(x_train,-1) #-1在最後一個位置增維
x_train=np.expand_dims(x_train,axis=1) #在第一個位子增維
```
- One Hot encoding
```python=
num_classes=10
y_train=keras.utils.to_categorical(y_train,num_classes)
#one hot encoding
```
## M8/M9
- [TED:how we're teaching computers to understand pictures](https://l.messenger.com/l.php?u=https%3A%2F%2Fwww.ted.com%2Ftalks%2Ffei_fei_li_how_we_re_teaching_computers_to_understand_pictures&h=AT04RotFlMtCjLHc-jtV3x-Vt-ASQqI9h4_mevaMshAIi8i0ummQxORprj6o3_CFfFQaMr4VoV3X3PuaiWCB3meAxUWOJHZ6X44kjmQMVlL2SsrroP9EhfzCmirJhQ2NmMwJ1A)
### 支持向量機(SVM)
- :+1: 線很漂亮、可做非線性的決策邊界
- :-1: 資料比數過大,時間複雜度高
SVM vs KNN?
### model評估方式
- loss function
- 殘差(residual)
- 混淆矩陣(Confusion matrix)
- 二元分類(TP那個)
- 三元
- Area under curve(AUC)
- 曲線下面積
- 二元分配能力如何
- 1~0.5
- F-score(F-measure)
- Precision (精確率):TP/(TP+FP)
- 測出來的/測出真的
- recall (靈敏度、招回率、真陽性率):TP/(TP+FN)
- 測出來的/全部真的 (有點像抓染疫黑數)
- F-score:(2Precision*recall)/(Precision+recall)
- ==調和平均數==
### 資料前處理
- 有序:Label encoding
- 無序:one hot encoding
## 實作
**cv2:**
```python=
img=cv2.imread("path") #讀取檔案
img=cv2.resize(img,(length,width)) #縮放
img=cv2.cvtColor(img,cv2.BGR2RGB) #轉換顏色 "BGR2RGB"(其中一個換色編碼)
y=keras.utils.to_categorical(y,class_counts) #one hot encoding
```