Machine learn in python Chapter 2 2.1.1, python2.1.1
1 about sklearn. datasets
From sklearn. datasets import load_iris
Import numpy as np
Data = load_iris ()
The data attributes are as follows:
Data is stored in. data
Classes of each observation object are stored in the .tar get attribute of the data set.
>>> 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 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 2 2 2 2 2 2 2 2 2 2 2 2
2 2]
The types of data features are stored in the. feature_names attribute of the dataset.
>>> Print (data ['target _ names'])
['Setsous' 'versicolor' 'virginica ']
2. traversal Problems
A: traversal does not take the serial number I of item
For item in sequence:
Process (item)
B:
For index, item in enumerate (sequence ):
Process (index, item)
3: subplot (m, n, I)
For example, subplot (2nd, 2) indicates dividing the entire plane into two rows and three columns. The graph to be drawn is located at the position in the order from left to right.
4 zip in python
Zip back list
X = [1, 2, 3, 4, 5] y = [6, 7, 8, 9, 10] zip (x, y, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
5 range () function
Range ([start,] stop [, step])
# Start (optional)
# Stop termination count, if range has only one parameter x, a list of integers containing 0 to X-1 is generated
# Step (optional)
6. If you encounter an annoying space problem, the following error occurs: IndentationError: expected an indented block.
For I in range (): enter a space
Space print (I) Press ENTER
Else: Press enter with a space
Space print ("") Press ENTER
>>> For I in range (1, 5 ):
... Print (I)
... Else:
... Print ("dead! ")
...
1
2
3
4
Dead!
In python, list = [[0 for a in range (8)] for B in range (8)] how to print a coordinate (x, y)
Create an 8x8 sequence table and access list [x] [y] In column y of row x.
Print the pirnt list [x] [y]
Self problems in python init
_ Init _ () is a class constructor called when an object is created. Self is a reference to the object itself. This is equivalent to this in c ++.
Python requires that this should be added before the handler class members. Here, this. name = name indicates that the property name is added to the Person class.
If this is not added before the variable, it is considered as a local variable. This variable will expire after the method is run. Attributes are valid throughout the class.
Thank you for your support!