--- title: 機器學習2 12/17 tags: 機器學習 --- 共筆: * [機器學習 - 12/16共筆 - Google 文件](https://docs.google.com/document/d/1bz5RBxq8FPoQkzA5Yr-0XMUcA_USesql9oyTFwTrTBA/edit#heading=h.581xx291vjkv) ## 分群 cluster * [sklearn.cluster.KMeans — scikit-learn 0.23.2 documentation](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html) ## kMeans(k中心):標籤V.S圓心 ![](https://i.imgur.com/pp5L9qY.png) 1. 隨機3圓心 2. 算距離歸群(固定 圓心) 3. 重選3圓心 (固定 標籤) 停止:次數上限/圓心受限小 ## KMeans(K個中心) :標籤vs圓心 1.隨機3圓心 2.算距離 把其他圓心歸群(固定圓心) 3.重選3圓心(固定標籤) 訂定停止條件1.次數上限2.圓心不變or變動很小 參考資料: * [機器學習: 集群分析 K-means Clustering. Python範例,MATLAB 範例 | by Tommy Huang | Medium](https://chih-sheng-huang821.medium.com/%E6%A9%9F%E5%99%A8%E5%AD%B8%E7%BF%92-%E9%9B%86%E7%BE%A4%E5%88%86%E6%9E%90-k-means-clustering-e608a7fe1b43) 看完技術文件後要看一下 attributes: ![](https://i.imgur.com/1P3zQ5b.png) 分群->自己填答案 沒有答案的時候做得分群動作 (分類前的前置動作) ### sklearn.metrics.silhouette_score * [sklearn.metrics.silhouette_score — scikit-learn 0.23.2 documentation](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html) ## seaborn 參考網址: * [seaborn: statistical data visualization — seaborn 0.11.0 documentation](https://seaborn.pydata.org/) ## seaborn.scatterplot¶ * [seaborn.scatterplot — seaborn 0.11.0 documentation](https://seaborn.pydata.org/generated/seaborn.scatterplot.html#seaborn.scatterplot) hue 會用顏色分出兩種類型 ![](https://i.imgur.com/r6ulMR9.png) ![](https://i.imgur.com/RiD1sno.png) ![](https://i.imgur.com/3FbCX6S.png) ## 中文處理 兩工具 都轉成繁體 或是都轉成簡體 * [yichen0831/opencc-python: OpenCC made with Python](https://github.com/yichen0831/opencc-python) colab 指令操作 linux指令 都可操作 `!ls- al ` 列出所有東西 `!python -version` pyrhon 版本 ------ ## 分群合理? 拿朋友親密程度&疏遠程度來舉例 親近:$\frac{1}{m}\sum_{i=1}^n \frac{1}{n}\sum_{j=1}^n (p_i-所在圈_j)^2 \quad$ 疏遠:$\frac{1}{m}\sum_{i=1}^n \frac{1}{n}\sum_{j=1}^n (p_i-最近圈_j)^2 \quad$ 假設 a = 親近, b = 疏遠 ------- ## jieba 功能: 分詞 關鍵字 TF IDF: TF詞頻 :次多、重要高 IDF常用度:次數出現高、重要低 重要性:次數* (1/常用度) 辭典->切割->上下文切割 辭典檔做得好 就不會分錯了 中文才需要分詞 ## jieba 在github下載 * [fxsjy/jieba: 结巴中文分词](https://github.com/fxsjy/jieba) 分數越高 表示越重要 若出現時會視為重要詞 ![](https://i.imgur.com/g0Jh2TX.png) ### 維度災難:欄位過多 1. 演算法出問題 資料要分類的種類多不多 輸出多不多:越多越難 欄位多不多:越多越難 2. 欄位越多 需要超多資料 ---- 機率 P(A) ->A事件發生的機率 P(A交集B) /P(A,B)-> A發生且B發生機率 P(A|B)/P(A/B):固定B, A發生機率(B不計算機率) 貝氏定理: p(A.B):P(A) --- modin 當pandas 資料太多無法處理時 可以用modin 操作上基本上跟pandas差不多 * [modin-project/modin: Modin: Speed up your Pandas workflows by changing a single line of code](https://github.com/modin-project/modin) ![](https://i.imgur.com/FZubEJn.png) --- 刪除欄位的學問 若演算法會自動選 則不用刪除:如 決策樹 若演算法不會自動選 也不用刪除 一般來說 不邀因為相關性問題 而刪除欄位 * [sklearn.feature_extraction.text.CountVectorizer — scikit-learn 0.23.2 documentation](https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html) train :fit _transform test: transform(現有) (忽略not in 訓練資料) 沒有出現在訓練資料中的東西 ->忽略 ### 單純貝氏 ### 核心機率