Why use python to implement machine learning algorithms?

Source: Internet
Author: User

For the following three reasons, we chose python as the programming language for implementing machine learning algorithms: (1) Clear Python syntax; (2) Easy to operate plain text files; (3) widely used, there are a large number of development documents.

Executable pseudocode

Python has a clear syntax structure and is also called executable pseudo-code ). The default Python development environment has many advanced data types, such as lists, tuples, dictionaries, collections, and queues. You can use these data types without further programming. Using these data types makes abstract mathematical concepts very simple. In addition, readers can also use familiar programming styles, such as object-oriented programming, process-oriented programming, or functional programming. If you are not familiar with python, refer to Appendix A, which describes the Python language, the data types used by python, and the installation guide.

The Python language is very simple to process and operate on text files and is very easy to process non-numeric data. The Python language provides a wide range of Regular Expression functions and many function libraries that access web pages, making extracting data from HTML very simple and intuitive.

Python is popular

The Python language is widely used and there are many code examples for readers to quickly learn and master. In addition, rich module libraries can be used to shorten the development cycle when developing practical applications.

Python is widely used in science and finance. Many scientific function libraries, such as scipy and numpy, implement vector and matrix operations. These function libraries increase code readability and allow anyone who has learned linear algebra to understand the actual functions of the Code. In addition, the science function library scipy and numpy are written in the underlying languages (C and Fortran), improving the computing performance of related applications. This book will use Python numpy in large quantities.

Python scientific tools can work with matplotlib. Matplotlib can draw 2D and 3D images, and can also process frequently used graphics in scientific research. Therefore, matplotlib will be widely used in this book.

The Python development environment also provides an interactive shell environment that allows users to view and detect program content during program development.

In the future, the python development environment will integrate the pylab module, which combines numpy, scipy, and matplotlib into a development environment. When writing this book, pylab has not yet been integrated into the python environment, but we will certainly find it in the python development environment in the near future.

Features of Python

Advanced Programming languages such as MATLAB and Mathematica also allow users to perform matrix operations. MATLAB even has many embedded features that can easily construct machine learning applications, and Matlab is fast in operation. However, the disadvantage of MATLAB is that software costs are too high, and a single software license costs thousands of US dollars. Although there are third-party plug-ins suitable for Matlab, there is no influential large open-source project.

Strong programming languages such as Java and C also have a matrix Math library. However, for these programming languages, the biggest problem is that a large amount of code is required even after simple operations. The programmer first needs to define the type of the variable. For Java, the getter and setter methods must be implemented each time the attribute is encapsulated. In addition, we also need to remember to implement subclasses. Even if we do not want to use subclasses, we must implement subclass methods. To do a simple job, we have to spend a lot of time writing a lot of useless and lengthy code. The Python language is completely different from Java and C. It is clear, concise, and easy to understand. Even if it is not a programmer, it can understand the meaning of the program, java and C are as hard to understand as they are for non-programmers.

Everyone has learned to write in the second year of elementary school, but most people must do other more important jobs.

-- Bobby Knight

Maybe one day, we can replace "writing" with "writing code" in this sentence. Although some people are interested in writing code, for most people, programming is just a tool to complete other tasks. Python is a high-level programming language. We can spend more time processing the internal meaning of data, instead of spending too much energy on how computers get data results. The Python language makes it easy for us to express our goals.

Disadvantages of Python

The only drawback of the Python language is the performance. Python programs run less efficiently than Java or C code, but we can use python to call C-compiled code. In this way, we can gradually develop machine learning applications by leveraging the advantages of C and python. First, we can use python to compile the experiment program. If we want to implement machine learning in the product, it is not difficult to convert it into C code. If the program is organized according to the modularization principle, we can first construct a runable Python program, and then gradually replace the core code with C code to improve the program performance. The C ++ boost library is suitable for this task. Other Tools similar to cython and pypy can also write strong Python code to Improve the Performance of General Python programs.

If the algorithm or idea of a program is defective, no matter what the program's performance is, no correct result can be obtained. If there is a problem in the idea of solving the problem, simply increasing the program running efficiency and expanding the user scale will not solve this core problem. From this perspective, the advantages of Python's rapid implementation of the system are even more obvious. We can quickly check whether algorithms or ideas are correct. If necessary, we can further optimize the code.

Note: This article is excerpted from "machine learning practices", which will be available around June 10.

Related Article

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.