"Machine learning Combat" Learning notes--k nearest neighbor algorithm

Source: Internet
Author: User

The use of some functions in 1.numpy learning

    • Shape () Usage:

shape : Tuple of INTs

The elements of the shape tuple give the lengths of the corresponding array dimensions.

Shape returns a tuple, which in turn is the length of each dimension. SHAPE[0]: First dimension length , Shape[1]: second dimension length.

  

    • Tile () Usage:

numpy.tile(A, reps)

Construct an array by repeating A, the number of times given by Reps.

If reps has length d , the result would have dimension of max(d, A.ndim) . (A.ndim represents the dimension of a matrix)

If A.ndim < d , A is promoted to being d-dimensional by prepending new axes. So A-shape (3,) array is promoted to (1, 3) for 2-d replication, or shape (1, 1, 3) for a-Z replication. If This isn't the desired behavior, promote A to d-dimensions manually before calling this function.

If A.ndim > d , Reps is promoted to A. Ndim by pre-pending 1 ' s to it. Thus for a A 's shape (2, 3, 4, 5), A reps of (2, 2) is treated as (1, 1, 2, 2).

Tile () Usage understanding is a bit difficult. Assuming that reps= (2,3,3), 2, 3, 3 respectively represent the number of repetitions in the 第一、二、三个 dimension, which is popularly the element in the 第一、二、三个 brackets. If the dimension of a is less than reps, the dimension is increased by 3, and if the dimension of A is greater than 3 (assuming 4), the default is reps= (1,2,3,3).

  

    • Slice of Numpy.array ()

For a one-dimensional array, the tile usage is the same as for Python, and for multidimensional arrays (matrices), X1 means to select the subscript x1 in the first dimension (The matrix is the X1 row), and X2 to start with the a[x1,x2:x3,x4 from the second dimension as X2, as follows:

  

Note: X2 is not allowed to appear alone, that is, cannot appear a[,x2:], otherwise it will be an error. Similarly, X3 represents the row subscript (the first dimension), and the X4 represents the column subscript (the second dimension). X3 indicates which row to select (without x3), X4 indicates that the X4 column is selected.

    • Argsort () Usage

  numpy.argsort(a, axis=-1, kind= ' quicksort ', order=none)

Returns the indices that would sort an array.

Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as a , the index data along the given axis in sorted order.

Returns an array of subscripts after a small to large order. Axis represents the dimension to compare, which defaults to the last dimension.

 

Some function learning in 2.python

The reload () function, which needs to be introduced from the IMP module: from IMP import reload

Raw_input () renamed as input () after python3.x

Listdir () in the OS module lists a list of all filenames under the path.

3. Code analysis (to be supplemented)

"Machine learning Combat" Learning notes--k nearest neighbor algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.