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!

版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-30 11:16  yxwkaifa  阅读(210)  评论(0)    收藏  举报