machine learn in python 第二章2.1.1
1大約 sklearn.datasets?
? from sklearn.datasets import load_iris
??import numpy as np
? data = load_iris()
data 的屬性例如以下:
數(shù)據(jù)存儲(chǔ)在.data項(xiàng)中
每一個(gè)觀察對(duì)象的種類存儲(chǔ)在數(shù)據(jù)集的.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]
數(shù)據(jù)的特征的種類存儲(chǔ)在數(shù)據(jù)集的.feature_names屬性中。
>>>print(data['target_names'])
['setosa' 'versicolor' 'virginica']
2關(guān)于遍歷問題
a:遍歷不取item的序號(hào)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)表示將整個(gè)平面劃分為2行3列,當(dāng)中如今要畫的圖位于從左到右的順序的第2個(gè)位置
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() 函數(shù)??? range([start,] stop [, step])
??? # start? 可選參數(shù),起始數(shù)
??? #stop?? 終止數(shù)。假設(shè) range 僅僅有一個(gè)參數(shù)x,則產(chǎn)生一個(gè)包括 0 至 x-1 的整數(shù)列表
??? #step?? 可選參數(shù),步長
6 煩人的空格問題 報(bào)錯(cuò):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!
版權(quán)聲明:本文博客原創(chuàng)文章,博客,未經(jīng)同意,不得轉(zhuǎn)載。
總結(jié)
以上是生活随笔為你收集整理的machine learn in python 第二章2.1.1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在matlab中将处理结果输出为shp文
- 下一篇: python binary lib on