machine learn in python 第二章2.1.1
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!
版權聲明:本文博客原創文章,博客,未經同意,不得轉載。
總結
以上是生活随笔為你收集整理的machine learn in python 第二章2.1.1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在matlab中将处理结果输出为shp文
- 下一篇: js调试工具console详解