<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 用于機器學習開發人員的 Python 崩潰課程 > 原文: [https://machinelearningmastery.com/crash-course-python-machine-learning-developers/](https://machinelearningmastery.com/crash-course-python-machine-learning-developers/) 您不需要成為 Python 開發人員就可以開始使用 Python 生態系統進行機器學習。 作為一名已經知道如何使用一種或多種編程語言編程的開發人員,您可以非常快速地選擇像 Python 這樣的新語言。您只需要了解該語言的一些屬性即可將您已知的語言轉換為新語言。 在這篇文章中,您將獲得 Python 的速成課程以及機器學習所需的核心庫。即:NumPy,MatPlotLib 和 Pandas。 這將是足夠的信息,可以幫助您閱讀和理解機器學習的代碼 Python 代碼示例,并開始開發自己的腳本。如果你已經知道一點 Python,這篇文章將是一個友好的提醒。 讓我們開始吧。 * **2017 年 3 月更新**:更新了所有可用于 Python 2 和 Python 3 的打印語句。 ![Crash Course in Python for Machine Learning Developers](https://img.kancloud.cn/2b/75/2b757f24aa2d2f50d5354a80ad8f3716_640x480.jpg) 用于機器學習開發人員的 Python 崩潰課程 攝影: [John Clouston](https://www.flickr.com/photos/58017169@N06/5353030024/) ,保留一些權利。 ## Python 速成課程 在 Python 入門時,您需要了解有關語言語法的一些關鍵細節,以便能夠閱讀和理解 Python 代碼。這包括: * 分配 * 流量控制 * 數據結構 * 功能 我們將依次使用您可以鍵入和運行的小型獨立示例來介紹這些主題。 請記住,whitespace 在 Python 中具有意義。 ### 分配 作為一名程序員,作業和類型不應該讓您感到驚訝。 #### 字符串 ``` # Strings data = 'hello world' print(data[0]) print(len(data)) print(data) ``` 運行示例打印: ``` h 11 hello world ``` #### 數字 ``` # Numbers value = 123.1 print(value) value = 10 print(value) ``` Running the example prints: ``` 123.1 10 ``` #### 布爾 ``` # Boolean a = True b = False print(a, b) ``` Running the example prints: ``` (True, False) ``` #### 多次分配 ``` # Multiple Assignment a, b, c = 1, 2, 3 print(a, b, c) ``` Running the example prints: ``` (1, 2, 3) ``` #### 沒有價值 ``` # No value a = None print(a) ``` Running the example prints: ``` None ``` ### 流量控制 您需要學習三種主要類型的流控制:If-Then-Else 條件,For-Loops 和 While-Loops。 #### If-Then-Else 條件示例 ``` value = 99 if value >= 99: print('That is fast') elif value > 200: print('That is too fast') else: print('That that is safe') ``` 運行此示例打印: ``` That is fast ``` #### For-Loop 示例 ``` # For-Loop for i in range(10): print(i) ``` Running this example prints: ``` 0 1 2 3 4 5 6 7 8 9 ``` #### While-Loop 示例 ``` # While-Loop i = 0 while i < 10: print(i) i += 1 ``` Running this example prints: ``` 0 1 2 3 4 5 6 7 8 9 ``` ### 數據結構 Python 中有三種數據結構,您會發現它們使用最多且最有用。它們是元組,列表和詞典。 #### 元組示例 元組是項目的只讀集合。 ``` a = (1, 2, 3) print(a) ``` Running the example prints: ``` (1, 2, 3) ``` #### 列表示例 列表使用方括號表示法,可以使用數組表示法進行索引。 ``` mylist = [1, 2, 3] print("Zeroth Value: %d" % mylist[0]) mylist.append(4) print("List Length: %d" % len(mylist)) for value in mylist: print(value) ``` Running the example prints: ``` Zeroth Value: 1 List Length: 4 1 2 3 4 ``` #### 字典示例 字典是名稱與值的映射,如地圖。請注意使用花括號表示法。 ``` mydict = {'a': 1, 'b': 2, 'c': 3} print("A value: %d" % mydict['a']) mydict['a'] = 11 print("A value: %d" % mydict['a']) print("Keys: %s" % mydict.keys()) print("Values: %s" % mydict.values()) for key in mydict.keys(): print(mydict[key]) ``` Running the example prints: ``` A value: 1 A value: 11 Keys: ['a', 'c', 'b'] Values: [11, 3, 2] 11 3 2 ``` ### 功能 Python 的最大問題是空白。確保縮進代碼后有一個空的新行。 下面的示例定義了一個新函數來計算兩個值的總和,并使用兩個參數調用該函數。 ``` # Sum function def mysum(x, y): return x + y # Test sum function print(mysum(1, 3)) ``` Running the example prints: ``` 4 ``` ## NumPy 速成課程 NumPy 為 SciPy 提供基礎數據結構和操作。這些是有效定義和操作的數組(ndarrays)。 ### 創建陣列 ``` # define an array import numpy mylist = [1, 2, 3] myarray = numpy.array(mylist) print(myarray) print(myarray.shape) ``` Running the example prints: ``` [1 2 3] (3,) ``` ### 訪問數據 數組表示法和范圍可用于有效地訪問 NumPy 數組中的數據。 ``` # access values import numpy mylist = [[1, 2, 3], [3, 4, 5]] myarray = numpy.array(mylist) print(myarray) print(myarray.shape) print("First row: %s" % myarray[0]) print("Last row: %s" % myarray[-1]) print("Specific row and col: %s" % myarray[0, 2]) print("Whole col: %s" % myarray[:, 2]) ``` Running the example prints: ``` [[1 2 3] [3 4 5]] (2, 3) First row: [1 2 3] Last row: [3 4 5] Specific row and col: 3 Whole col: [3 5] ``` ### 算術 NumPy 數組可以直接用于算術運算。 ``` # arithmetic import numpy myarray1 = numpy.array([2, 2, 2]) myarray2 = numpy.array([3, 3, 3]) print("Addition: %s" % (myarray1 + myarray2)) print("Multiplication: %s" % (myarray1 * myarray2)) ``` Running the example prints: ``` Addition: [5 5 5] Multiplication: [6 6 6] ``` NumPy 數組還有很多,但這些例子可以讓您了解它們在處理大量數值數據時所提供的效率。 ## Matplotlib 速成課程 Matplotlib 可用于創建圖表和圖表。 該庫通常使用如下: 1. 使用一些數據調用繪圖函數(例如 plot())。 2. 調用許多函數來設置繪圖的屬性(例如標簽和顏色)。 3. 使圖可見(例如 show())。 ### 線圖 下面的示例從一維數據創建一個簡單的線圖。 ``` # basic line plot import matplotlib.pyplot as plt import numpy myarray = numpy.array([1, 2, 3]) plt.plot(myarray) plt.xlabel('some x axis') plt.ylabel('some y axis') plt.show() ``` 運行該示例會產生: ![Simple Line Plot in Matplotlib](https://img.kancloud.cn/c6/f3/c6f3fa189633128fd060618373427507_800x600.jpg) Matplotlib 中的簡單線圖 ### 散點圖 下面是從二維數據創建散點圖的簡單示例。 ``` # basic scatter plot import matplotlib.pyplot as plt import numpy x = numpy.array([1, 2, 3]) y = numpy.array([2, 4, 6]) plt.scatter(x,y) plt.xlabel('some x axis') plt.ylabel('some y axis') plt.show() ``` Running the example produces: ![Simple Scatter Plot in Matplotlib](https://img.kancloud.cn/bf/a0/bfa08e6ef5a967ca4cba0afb0cb7cc01_800x600.jpg) Matplotlib 中的簡單散點圖 還有更多的繪圖類型和更多可以在繪圖上設置的屬性來配置它。 ## 熊貓速成課程 Pandas 提供數據結構和功能,以快速操作和分析數據。理解 Pandas 機器學習的關鍵是理解 Series 和 DataFrame 數據結構。 ### 系列 系列是一維數組,其中可以標記行和列。 ``` # series import numpy import pandas myarray = numpy.array([1, 2, 3]) rownames = ['a', 'b', 'c'] myseries = pandas.Series(myarray, index=rownames) print(myseries) ``` Running the example prints: ``` a 1 b 2 c 3 ``` 您可以像 NumPy 數組一樣訪問數據,例如字典,例如: ``` print(myseries[0]) print(myseries['a']) ``` Running the example prints: ``` 1 1 ``` ### 數據幀 數據幀是多維數組,其中可以標記行和列。 ``` # dataframe import numpy import pandas myarray = numpy.array([[1, 2, 3], [4, 5, 6]]) rownames = ['a', 'b'] colnames = ['one', 'two', 'three'] mydataframe = pandas.DataFrame(myarray, index=rownames, columns=colnames) print(mydataframe) ``` Running the example prints: ``` one two three a 1 2 3 b 4 5 6 ``` 數據可以使用列名稱進行索引。 ``` print("one column: %s" % mydataframe['one']) print("one column: %s" % mydataframe.one) ``` Running the example prints: ``` one column: a 1 b 4 one column: a 1 b 4 ``` ## 摘要 你已經在這篇文章中介紹了很多內容。您發現了 Python 的基本語法和用法以及用于機器學習的四個關鍵 Python 庫: * NumPy 的 * Matplotlib * 熊貓 您現在已經掌握了足夠的語法和用法信息,可以閱讀和理解用于機器學習的 Python 代碼并開始創建自己的腳本。 您對本文中的示例有任何疑問嗎?在評論中提出您的問題,我會盡力回答。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看