<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Peter on Medium]]></title>
        <description><![CDATA[Stories by Peter on Medium]]></description>
        <link>https://medium.com/@mylifeai1116?source=rss-452309d2f2cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T8oy0SLfi5q8OAZu3PhBCg.jpeg</url>
            <title>Stories by Peter on Medium</title>
            <link>https://medium.com/@mylifeai1116?source=rss-452309d2f2cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:21:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mylifeai1116/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deep Learning Book 筆記]]></title>
            <link>https://medium.com/@mylifeai1116/deep-learning-book-%E7%AD%86%E8%A8%98-bb46f6d6adc2?source=rss-452309d2f2cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb46f6d6adc2</guid>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Peter]]></dc:creator>
            <pubDate>Fri, 11 May 2018 16:53:22 GMT</pubDate>
            <atom:updated>2018-05-11T17:11:22.434Z</atom:updated>
            <content:encoded><![CDATA[<h4>前言</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/0*kLa8ATSNbfe1_tcC.jpg" /></figure><p>此書</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb46f6d6adc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用Sklearn學習分類和分群]]></title>
            <link>https://medium.com/@mylifeai1116/%E4%BD%BF%E7%94%A8sklearn%E5%AD%B8%E7%BF%92%E5%88%86%E9%A1%9E%E5%92%8C%E5%88%86%E7%BE%A4-5565258e9a3a?source=rss-452309d2f2cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/5565258e9a3a</guid>
            <dc:creator><![CDATA[Peter]]></dc:creator>
            <pubDate>Sat, 07 Apr 2018 12:35:15 GMT</pubDate>
            <atom:updated>2018-04-07T12:46:59.122Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>本文分別說明 Clustering 和 Classification</em></blockquote><blockquote><em>Clustering : 使用 Kaggle 的 </em><a href="https://www.kaggle.com/unsdsn/world-happiness"><em>World Happiness report</em></a><em><br>Classification：使用Kaggle的</em><a href="https://www.kaggle.com/uciml/breast-cancer-wisconsin-data/kernels">Breast Cancer Wisconsin (Diagnostic) Data Set</a></blockquote><blockquote><em>本人剛踏入資料分析和機器學習領域，主要研究方向是類神經網路，對於其他演算法較少觸碰，若是文中有錯誤，再麻煩大家不吝指教。</em></blockquote><h3>Clustering</h3><h4>資料介紹</h4><p>World Happiness Report 是全球幸福狀況的報告，2017年的報告在國際快樂日(3/20)發表。其中資料有以下：</p><ol><li>Country：國家</li><li>Region：地區</li><li>Happiness Rank：幸福等級，根據幸福分數來排名</li><li>Happiness Score：幸福分數，問題採用 Cantril ladder，讓受試者對於目前生活的平活，分數為1–10分</li><li>Economy(GDP)：國內生產總值</li><li>Family：家庭分數</li><li>Health (Life Expectancy)：壽命(健康)分數</li><li>Freedom：自由度</li><li>Trust：對政府的信任程度</li></ol><h4>資料前處理</h4><p>一開始先將所需的套件匯入，這邊使用到的套件如下:</p><ol><li>numpy: 支援高階大量的維度陣列與矩陣運算，此外也針對陣列運算提供大量的數學函式函式庫。</li><li>pandas：基於numpy之上的套件，主要使用於表格化的資料。</li><li>matplotlib、seaborn：python中常用的繪圖工具。</li><li>plotly.graph_objs：繪製世界地圖的套件。</li></ol><p>這邊我是用pandas讀取2017年的幸福指數，程式碼如下：</p><pre># 常用資料處理模組<br>import numpy as np<br>import pandas as pd    <br># 可視化模組<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>import plotly.plotly as py<br># 世界地圖套件<br>import plotly.graph_objs as go<br>from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot<br>init_notebook_mode(connected=True)<br>%matplotlib inline<br>sns.set_context(&#39;poster&#39;)<br>sns.set_color_codes()</pre><pre>sns.set(style=&quot;whitegrid&quot;, palette=&quot;muted&quot;)<br>current_palette = sns.color_palette()<br># 讀取csv放入df中<br>df = pd.read_csv(&quot;2017.csv&quot;)</pre><p>接著來看看資料中的Happiness.Score欄位，此參數越大排名就會越前面，將參數化使用世界地圖可視化，程式碼如下：</p><pre># 可視化幸福指數<br>data = dict(type = &#39;choropleth&#39;, <br>           locations = df[&#39;Country&#39;],<br>           locationmode = &#39;country names&#39;,<br>           z = df[&#39;Happiness.Score&#39;], <br>           text = df[&#39;Country&#39;],<br>           colorbar = {&#39;title&#39;:&#39;Happiness&#39;})<br>layout = dict(title = &#39;Global Happiness&#39;, <br>             geo = dict(showframe = False, <br>                       projection = {&#39;type&#39;: &#39;Mercator&#39;}))<br>choromap3 = go.Figure(data = [data], layout=layout)<br>iplot(choromap3)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfwwwT0IPdGJS1p4jL3Rvw.png" /><figcaption>幸福指數分布圖</figcaption></figure><h4>KMeans</h4><p>使用最常見的KMeans來分析吧!這邊使用python的sklearn，</p><pre>from sklearn.cluster import KMean</pre><p>前文有使用pandas讀取資料並放入pd中，這邊取欄位2~11(因為第一欄為國家名字、第二欄為排名，並不是我們要分析的資料)</p><pre># 取出除了國家和排名的其他特徵<br>df_feature = df.iloc[:,2:11]<br># 顯示選取的特徵<br>df_feature</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*fOvDVuEPDCPZadUspc4ZZg.png" /><figcaption>篩選過的資料表(部分顯示)</figcaption></figure><p>將分類好後的每個類別個數繪製成直方圖，程式碼如下：</p><pre># 使用KMeans分類，K=5<br>cluster = KMeans(n_clusters=5)<br>cluster.fit(df_feature)<br># 繪製分類的直方圖<br>plt.xlabel(&#39;cluster group&#39;)<br>plt.ylabel(&#39;count&#39;)<br>bins = np.arange(0, 5, 0.5) # fixed bin size<br>plt.hist(cluster.labels_, bins=bins)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*qCCHWLya8ytVFdaIUimpzA.png" /></figure><p>使用plotly.graph_objs模組將各區域對應的分類畫出來，程式碼如下</p><pre># 可視化分類結果<br>data = dict(type = &#39;choropleth&#39;, <br>           locations = df[&#39;Country&#39;],<br>           locationmode = &#39;country names&#39;,<br>           z = cluster.labels_, <br>           text = df[&#39;Country&#39;],<br>           colorbar = {&#39;title&#39;:&#39;Cluster group&#39;, &quot;nticks&quot;: 5})<br>layout = dict(title = &#39;KMeans&#39;, <br>             geo = dict(showframe = False, <br>                       projection = {&#39;type&#39;: &#39;Mercator&#39;}))<br>choromap3 = go.Figure(data = [data], layout=layout)<br>iplot(choromap3)</pre><p>注意：這邊是指分群的結果，所以顏色不代表幸福或不幸福，不過由分類可以看出幸福指數似乎和鄰近的國家很有關聯性。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*bZzH43qwL_U8fjFVD-ViFg.png" /></figure><h4>SpectralClustering</h4><p>首先匯入SpectralClustering套件，並且設定K=5分為五類，程式碼如下：</p><pre>from sklearn.cluster import SpectralClustering<br># 使用SpectralClustering分類，K=5<br>cluster = SpectralClustering(n_clusters=5)<br>cluster.fit(df_feature)</pre><p>使用plotly.graph_objs模組將各區域對應的分類畫出來，程式碼如下：</p><pre># 可視化分類結果<br>data = dict(type = &#39;choropleth&#39;, <br>           locations = df[&#39;Country&#39;],<br>           locationmode = &#39;country names&#39;,<br>           z = cluster.labels_, <br>           text = df[&#39;Country&#39;],<br>           colorbar = {&#39;title&#39;:&#39;Cluster group&#39;, &quot;nticks&quot;: 5})<br>layout = dict(title = &#39;SpectralClustering&#39;, <br>             geo = dict(showframe = False, <br>                       projection = {&#39;type&#39;: &#39;Mercator&#39;}))<br>choromap3 = go.Figure(data = [data], layout=layout)<br>iplot(choromap3)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*uwBVO8CHvhLnddxPv6TecQ.png" /></figure><h3>Classification</h3><h4>資料介紹</h4><p>Wisconsin州的乳癌資料，使用 fine needle aspirate (FNA)診斷是否為惡性腫瘤，病人訊息如下</p><ol><li>ID</li><li>良性或惡性</li></ol><p>乳房腫瘤的特徵訊息如下：</p><ol><li>半徑</li><li>紋理(灰階的標準偏差)</li><li>週長</li><li>區域</li><li>圓滑度</li><li>緊密度(週長² / 區域- 1.0)</li><li>凹度(輪廓凹部的嚴重性)</li><li>凹點(輪廓的凹入部分的數量)</li><li>對稱度</li><li>fractal dimension (“coastline approximation” — 1) &gt; 沒有很懂這個參數的意思</li></ol><h4>目標：使用這10個特徵值預測腫瘤為良性或惡性</h4><h4>資料前處理</h4><p>與上文相似，先匯入所需套件</p><pre>import numpy as np<br>import pandas as pd<br>from sklearn.neighbors import KNeighborsClassifier<br>from sklearn import cross_validation<br>from sklearn.preprocessing import Imputer<br># 資料可視化套件<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>%matplotlib inline</pre><p>使用pandas讀取資料，這邊有一筆資料室NAN會導致後面出問題，所以使用drop把這筆資料拋除，如下：</p><pre>df = pd.read_csv(&#39;data.csv&#39;)<br>df.drop(&quot;Unnamed: 32&quot;,axis=1,inplace=True)</pre><p>繪製良性和惡性的直方圖</p><pre>y = df.diagnosis <br>ax = sns.countplot(y,label=&quot;Count&quot;)       # M = 212, B = 357<br>B, M = y.value_counts()<br>print(&#39;Number of Benign: &#39;,B)<br>print(&#39;Number of Malignant : &#39;,M)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*9ymRSYS5O8GuwtorRMMYgw.png" /></figure><p>篩選出所需要的資料和標籤欄位，程式碼如下：</p><pre>data = df.iloc[:, 5:]<br>labels = df.iloc[:, 1]</pre><h4>KNN</h4><pre>x_train, x_test, y_train, y_test = cross_validation.train_test_split(data,labels, test_size=0.4, random_state=1 )<br>knn = KNeighborsClassifier(n_neighbors=5)<br>knn.fit(x_train, y_train)</pre><p>訓練資料的準確率為：0.94134897360703818<br>測試資料的準確率為：0.91228070175438591</p><pre>print(knn.score(x_train, y_train))<br>print(knn.score(x_test, y_test))</pre><h4>Neural Network</h4><p>匯入所需套件，如下：</p><pre>from sklearn.neural_network import MLPClassifier</pre><p>訓練神經網路，在訓練資料集下，可以得到準確率為0.897360703812；在測試資料集下，準確率為0.868421052632，程式碼如下：</p><pre>nn = MLPClassifier()<br>nn.fit(x_train, y_train)<br>print(nn.score(x_train, y_train))<br>print(nn.score(x_test, y_test))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*Mg0A_2I2XYETDZocZHR-kA.png" /><figcaption>繪製訓練過程中loss值，如下：</figcaption></figure><pre>plt.figure(1, figsize=(14, 13))<br>plt.clf()<br>plt.axes([.2, .2, .7, .7])<br>plt.plot(nn.loss_curve_, linewidth=2)<br>plt.axis(&#39;tight&#39;)<br>plt.xlabel(&#39;n_components&#39;)<br>plt.ylabel(&#39;explained_variance_ratio_&#39;)</pre><p>謝謝大家看到最後！其實我找的資料都是很簡單的資料(掃墓完才想起要交作業QAQ)，此份報告的總結如下：</p><ol><li>神經網路在資料數少的時候容易進入過擬和，所以在資料少的時候可以使用KNN處理即可(殺雞焉用牛刀?)</li><li>大概了解SKlearn，不過只是皮毛，了解自己還有很多東西要碰阿OAO</li><li>這次使用到世界地圖的套件，在解釋世界性的資料表現得比較好</li><li>我再匯入幸福指數時發現，發現2015年我們叫做台灣，2017年變成中國台灣省了，真是悲劇Q</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5565258e9a3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用python分析World Happiness]]></title>
            <link>https://medium.com/@mylifeai1116/%E4%BD%BF%E7%94%A8python%E7%9A%84sklearn%E5%88%86%E6%9E%90%E4%B8%96%E7%95%8C%E5%B9%B8%E7%A6%8F%E6%8C%87%E6%95%B8-fa60c1f217d5?source=rss-452309d2f2cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa60c1f217d5</guid>
            <dc:creator><![CDATA[Peter]]></dc:creator>
            <pubDate>Sat, 07 Apr 2018 02:37:08 GMT</pubDate>
            <atom:updated>2018-04-07T03:05:24.887Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>本文分別說明 Clustering 和 Classification</em></blockquote><blockquote><em>Clustering : 使用 Kaggle 的 </em><a href="https://www.kaggle.com/unsdsn/world-happiness"><em>World Happiness report</em></a></blockquote><blockquote><em>本人剛踏入資料分析和機器學習領域，主要研究方向是類神經網路，對於其他演算法較少觸碰，若是文中有錯誤，再麻煩大家不吝指教</em></blockquote><h3>Clustering</h3><h4>資料介紹</h4><h4>前處理</h4><p>一開始先將所需的套件匯入，這邊使用到的套件如下:</p><ol><li>numpy: 支援高階大量的維度陣列與矩陣運算，此外也針對陣列運算提供大量的數學函式函式庫。</li><li>pandas：基於numpy之上的套件，主要使用於表格化的資料。</li><li>matplotlib、seaborn：python中常用的繪圖工具。</li><li>plotly.graph_objs：繪製世界地圖的套件。</li></ol><p>這邊我是用pandas讀取2017年的幸福指數，程式碼如下：</p><pre># 常用資料處理模組<br>import numpy as np<br>import pandas as pd    <br># 可視化模組<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>import plotly.plotly as py<br># 世界地圖套件<br>import plotly.graph_objs as go<br>from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot<br>init_notebook_mode(connected=True)<br>%matplotlib inline<br>sns.set_context(&#39;poster&#39;)<br>sns.set_color_codes()</pre><pre>sns.set(style=&quot;whitegrid&quot;, palette=&quot;muted&quot;)<br>current_palette = sns.color_palette()<br># 讀取csv<br>df = pd.read_csv(&quot;2017.csv&quot;)</pre><p>接著來看看資料中的Happiness.Score欄位，此參數越大排名就會越前面，將參數化使用世界地圖可視化，程式碼如下：</p><pre># 可視化幸福指數<br>data = dict(type = &#39;choropleth&#39;, <br>           locations = df[&#39;Country&#39;],<br>           locationmode = &#39;country names&#39;,<br>           z = df[&#39;Happiness.Score&#39;], <br>           text = df[&#39;Country&#39;],<br>           colorbar = {&#39;title&#39;:&#39;Happiness&#39;})<br>layout = dict(title = &#39;Global Happiness&#39;, <br>             geo = dict(showframe = False, <br>                       projection = {&#39;type&#39;: &#39;Mercator&#39;}))<br>choromap3 = go.Figure(data = [data], layout=layout)<br>iplot(choromap3)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfwwwT0IPdGJS1p4jL3Rvw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa60c1f217d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>