machine learn in python 第二章2.1.1

來源:互聯網
上載者:User

1關於 sklearn.datasets 

  from sklearn.datasets import load_iris

  import numpy as np

  data = load_iris()

data 的屬性如下:


資料存放區在.data項中

每個觀察對象的種類儲存在資料集的.target屬性中

>>>print( target)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2
 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
 2 2]

資料的特徵的種類儲存在資料集的.feature_names屬性中。

>>>print(data['target_names'])
['setosa' 'versicolor' 'virginica']

2關於遍曆問題

a:遍曆不取item的序號i

for item in sequence:

 process(item)

b:

for index, item in enumerate(sequence):

 process(index, item)

3:subplot (m,n,i)

例如 subplot(2,3,2)表示將整個平面劃分為2行3列,其中現在要畫的圖位於從左至右的順序的第2個位置

4 zip in python

zip返回列表
x=[1, 2, 3, 4, 5 ]y=[6, 7, 8, 9, 10]zip(x, y)就得到了[(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
5 range() 函數
 

    range([start,] stop [, step])

    # start  選擇性參數,起始數

    #stop   終止數,如果 range 只有一個參數x,則產生一個包含 0 至 x-1 的整數列表

    #step   選擇性參數,步長6 煩人的空格問題 報錯:IndentationError: expected an indented block for i in range(1,5): 空格 斷行符號

空格print(i)斷行符號

else: 空格 斷行符號

空格print("")斷行符號斷行符號

>>> for i in range(1,5): 
...  print(i)
... else: 
...  print("dead!")
... 
1
2
3
4
dead!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.