Python libraries for machine learning

In this tutorial, you will learn about Python libraries for machine learning with example ( python machine learning library) and python packages for machine learning with example. The definition of the ML is allowing the computers to learn and ob serve the dataset to access the properties of data. The web technology is growing the analyses of data is based on pattern by human intervention and the computer programs are developed who can analyze the data. The science of programming a computer by which the computer will be able to learn from the data. In other words ML is field of study given by computer the ability to learn programmed and solve the real life problems. The previous process of performing the ML is by manual coding the algorithms and statistical formulas. But this process required much time and tedious but nowadays it has become easier. The python language has become popular for the task of ML and replaced by many languages in the IT industry. The process of Ml is dependent on the python libraries. The libraries are set for the functions and written in the language. The Ml is based on the statistics, mathematics and optimization

Why we use Python language for machine learning :-

  1. The language of python is reliable and less complexity.
  2. Anyone can understand and make it easy to understand.
  3. The data scientist can make ML to analyze data and draw useful insights with less effort.
  4. The language will support popular build in libraries and readily used to provide ML functionality.
  5. The library have 0 learning curve and understand of python allows the programmers to implement ready to use library.

It is used by the scientists those who task need to be integrated with web apps.
Python is mainly used in the ML field and its combination consists of syntax, development and flexibility which makes well suitable.

Python libraries for machine learning :-

The libraries used in the python language for machin learning are as follows:-

  1. Keras
  2. Scikit-learn
  3. TensorFlowPython
  4. Pandas
  5. Scipy
  6. Sympy
  7. Shogun
  8. Pytorch
  9. Theano
  10. Nuumpy ml package
  11. matplotlib
  12. Keras:-

The keras is the coolest ML library used in the python programming language. The beginners in learning ML should use the keras library because it is the easiest and express neutral networks. The utilities are provided by keras for processing, compiling models and visualization of the graphs. The keras use either Theano or Tensorflow as backend internally also we can use other networks as CNTK. The keras library is slow as compared to other libraries and the reason is because it constructs a graph using the backend infrastructure then uses it. The model of keras are portable and provides many preprocessed data sets and models like squeezeNet,VGG,ResNet,etc. It is developed by francois chollet for research and has integrated as part of tensorflow. It provides the API and work with pre trained of models like AlexNET, VGG.

Machine learning libraries Advantages:-

It is easy to understand and helps in the rapid prototyping.
The capability to work for low level library is like theano, mznet, etc.

Machine learning libraries Disadvantages:-

The performance is dependent on the backend which is used.
The high level library will make it difficult to develop custom components and the loss of functions.

Python libraries for machine learning Example:-

import torch
dtype=torch. float
device=torch. device (“cpu”)
N, D_in, H, D_out=64, 1000, 100, 10
x=torch.randn (N.D_in, device=device, type=dtype)
y=torch.randn (N.D_in, device=device, type=dtype)
w1=torch.randn (D_in, H, device=device, type=dtype)
w2=torch.randn (H.D_out, device=device, type=dtype)
learning_rate=1e-6
for t in range(500):
h=x.mm (w1)
h_relu=h.clamp (min=0)
y_pred=h_relu.mm (w2)
loss= (y_pred-y).pow (2).sum ().item ()
print(t, loss)
grad_y_pred=2/0*(y_pred-y)
grad_w2=h_relu.t ().mm (grad_y_pred)
grad_h_relu=grad_y_pred.mm (w2.t ())
grad_h=grad_h_relu.clone ()
grad_h [h<0] =0
grad_w1=x.t ().mm (grad_h)
w1=learning_rate*grad_w1
w2=learning_rate*grad_w2
Output:-
047168344.0
146385584.0
……..
4993.897604

2. Scikit-learn for the working with Ml algorithms:-

This library is most popular in the ML of the python programming language. The examples of these libraries will include the decision trees-means and so on. The scikit learn will build the basic libraries called as scipy and the Numpy. It will add the algorithm set for common ML and the data mining task. The non voice Ml will use the scikit learn tool to work with the algorithms. The scikit will provide the powerful transform and paradigm to learn data and transform the data.

Advantages:-

  1. Go-to package has the classical ML algorithms.
  2. The scikit is consistent and easy to understand for the transform and fit function.
  3. The capability to help the rapid prototyping having quick and reliable deployment.

Disadvantages:-

  1. Lack of ability to use the data for algorithm which support data types.
  2. There is heavy reliance in the scipy stack.

Scikit-learn for the working with Ml algorithms Example:-

from sklearn import datasets
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
dataset=datasets.load_iris ()
model=DecisionTreeClassifier ()
print(Model)
expected=dataset. target
predicted=model. predict (dataset.data)
print(metrics.classification_report (expected. predicted))
print(metrics.confusion_matrix (expected. predicted)
Output:-
DecisionTreeClassifier(class_weight=none, criterion=’gini’, max_depth=none, max_features=None, max_leaf_nodes=None)
Min_impurity_decreases=0.0, min_impurity_split=none, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, presort=False, random_state=none, splitter=’best’)
precision recall f1-score support


0

1

1.0

1.0

50

1

1

1.0

1.0

50

2

1

1.0

1.0

50

Micro avg

1

1.0

1.0

150

Micro avg

1

1.0

1.0

150

Weighted avg

1

1.0

1.0

150

[[50 0 0]
[0 50 0]
[0 0 50]]

3. Tensorflow:-

It is developed by the goggles use by the Google engineers and system is applied for variety of domains. This library is used for the dataflow programming and used as the symbolic math library used for different techniques to make the calculation. The python package is used for many applications of the ML and also referred as framework for ML. This library will provide scalable and robust solution foe computing of data sets. It is extensible and supports numerous platforms that provide GPU for the faster computations. This will improve the performance and support numerous platforms, visualization. It will also provide the algorithms for classification and the differentiation. The tensorflow library will also provide the algorithms API and speech recognition using the Natural language processing.

Advantages:-

  1. The debugging will help us to execute the graph and give upper hand and introduce, retrieve the data.
  2. The library management is important has the advantage for quick updates with new features.
  3. This library is designed for the backend softwares and is parallel.
  4. The performance is good and matches with the industry.

Disadvantages:-

  1. The Tensorflow will do not support the open CL.
  2. The speed is less and its usage also as compared to others.
  3. It will not satisfy the users and install the conda for the python pip library.

Tensorflow Example:-

import tensorflow as tf
x1=tf.constant ([1, 2, 3, 4])
x2=tf.constant ([5, 6, 7, 8])
result=tf.multiply(x1, x2)
sess=tf.Session ()
print(sess.run (result))
sess.close
Output:-
[5 12 21 32]

4. Pandas :-

The best and popularly used library for the data analysis is the pandas. This library is related to the ML from the python programming language. The pandas have data extraction and preparation techniques which provide data structure for data analysis. The pandas will also provide inbuilt methods for combining and filtering of data. The pandas will think on the relational data and library will provide expressive data structures for the data manipulation. It is faster and used in the programming language. The pandas are the open souce library which is used to perform the data manipulation in the python language. This library is build on top of Numpy and need the Numpy to operate. The library will provide easy way to create and manipulate and provide elegant solution. Pandas interface is used to express images and sound waves of streams as arrays of real numbers with N dimensions. The Numpy is very much important for Machine Learning and Data Science. Pandas is also called as the python package and operate at the fastest sped and designed to make working with ‘relationa’ and ‘labeled’.
Advantages:-

  1. It is easy library to use and have small curves to handle the data.
  2. It is compatible with numpy and go to choice of the ML like scikit-learn.
  3. It is set of utilities used to transform and write multiple formats.

Disadvantages:-

  1. The memory utilization is at high range so pandas will create the objects for quick access and manipulation.
  2. The pandas can format HDFS files but cannot utilize the distributed system to improve performance.

Pandas Example:-

          

import pandas as pd
data={“country”:[“Brazil”,”Russia”,”India”,”china”,”south Africa”],”capital”:[“Brasilia”,”Moscow”,”New Delhi”,”Beijing”,”Pretoria”],”area”:[8.5,17.10,3.28,9.5,1.22],”population”:[200.4,43.5,1252,1357,52.98]}
            Data_table=pd.Dataframe (data)
            Print(data_table)
Output:-

Python libraries for machine learning

5. Scipy :-

This is python library build by the Numpy and uses the Numpy arrays. The pronunciation is as sigh-pie important library used all the times. This is widely used for computing library for the python programming. The scipy is used for performing the operations like the probability, integration and regression. The scipy is used in the ML and contains the modules for linear algebra and the optimization. The difference between the scipy library and scipy stack is the image manipulation.

Example:-
from scipy.misc import imreas, imsave, imresize
img=imread (‘D: /programs/cat.jpg’)
print(img.dtype, img, shape)
img_tint=img*[1, 0.45, 0.3]
imsave (‘D: /Programs/cat_tinted.jpg’, img_tint)
Img_tint_resize=imresize (img_tint, (300,300))
Imsave(‘D: /programs/cat_tinted_resized.jpg’, img_tint_resize)
Output:-

  

Original image:
python machine learning library
Tinted image:
python packages for machine learning libraries
Resized tinted image:
machine learning Python libraries

6. Sympy:-

The sympy is the symbolic computation python library which focuses on the algebraic computation. The data scientist uses the symbolic computation and focus on the algebraic computation. They use for the intermediate analysis of data and consumed by the ML libraries in the python programming.
Example:-
From sympy import *a=Rational(5, 8)
Print(“value of a is:”+str(a))
B=Integer(3.5)
Print(“value of b is:”+str (b))
Output:-
Value of a is: 1/2
Value of b is: 3

7. Shogun:-

This library is free and open source toolbox used for the implementation in ML as the c++ language. It will support the interface of multiple languages as the Ruby, c#, java, python etc and the platforms as macOS, Linux, Windows. The shogun is free of cost and can be used by any scientist, journalist, students, etc. The shogun will provide the effective implementation of algorithms like hypothesis, kernel learning, etc. The library will come with the binary installation of the packages and provide an extensive testing infrastructure.
The shogun can scale the OS and process about 10 million of data samples accurately. The shogun is available for the educational purposes at universities and acts as non commercial.

8. PyTorch:-

The Tensorflow is used to write a program in the python language and you can compile, run on the CPU or GPU. Its use is for multilayered nodes which allow for the quick setup and work with large data sets. It will allow Google to identify the objects in a photo or understand spoken data in the voice recognition application.
Advantages:-

  1. It is a faster framework for deep learning.
  2. The Pytorch can handle the graphs to static ones and used by the counterpart.
  3. The implementation will help in seamless integration with objects and Numpy syntax.

Disadvantages:-

  1. The limited capabilities are present like the visualization and debugging as compared to complete suit in the Tensorflow.
  2. The gaining from ground and support is present.

PyTorch Example:-

import torch
dtype=torch. float
Device=torch. device(“cpu”)
N, D_in, H, D_out=64, 1000, 100, 10
x=torch.randn (N, D_in, device=device, dtype=dtype)
x=torch.randn (N, D_out, device=device, dtype=dtype)
x=torch.randn (D_in, H, device=device, type=dtype)
x=torch.randn (H, D_out, device=device, type=dtype)
learning_rate=1e-6
Fort in range(500):
H=x.mm (w1)
H_relu=h.clamp(min=0)
y_pred=h_relu.mm(w2)
loss= (y_pred-y).pow (2).sum ().item ()
print(t, loss)
grad_y_pred=2.0*(y_pred-y)
grad_w2=h_relu.t ().mm (grad_y_pred)
grad_h_relu=grad_y_pred.mm (w2.t ())
grad_h=grad_h_relu.clone ()
grad_w1=x.t ().mm (grad_h)
W1-=learning rate*grad_w1
W2-=learning rate*grad_w2
Output:-
0 47168
1 46378


497 3.98e-05

9. Theano:-

Theano is the python library used for the numerical calculation and is the same as the Numpy. It will allow defining, optimizing and evaluating the mathematical expressions involved in multidimensional arrays. It is used for the computation library used for the implementation and the network models. The advantage of the GPU and allow to make the data calculations 100 times faster than CPU. This library will allow for the creation of graphs for computing and provide symbolic differentiation. Theano library is the platform-independent and also provide a unit testing platform for error detection.
Example:-
import theano
import theano.tensor as T
x=T.dmatrix (‘x’)
s=1/ (1+T.exp (-x))
logistic=theano.function ([x], s)
logistics([[0, 1], [-1,-2]])
Output:-
arrays([[0.5, 0.73], [0.2, 0.11]])

10. Python Numpy Library:-

The full form of the Numpy is the “numerical python”. The Numpy is the python package and used for the logical and mathematical operations. They will support the algebra operations and the number generation process. This is build-in function and supports the dimensional array to perform the complex mathematical operations. The numpy is also called as the data handling library and allow large multidimensional arrays. The tensorflow and other libraries used the Numpy and acts as array interface.
Numpy Library Advantages:-

  1. It is highly efficient data structure which has good performance and handles the garbage collection.
  2. The capability will improve the performance and parallelization capabilities.
  3. The matrix and manipulation capability is like the reshape and transpose.

Numpy Library Disadvantages:-

  1. The performance of Numpy is very costly and the data type is native to the hardware.
  2. The dependency is upon the cython and c/c++ libraries used for numpy.

Python Numpy Library Example:-

Print(my_2d_array.shape)
Print(my_2d_array.data)
Print(my_2d_array.dtype)
Print(my_2d_array.strides)
Output:-
(2, 4)
Int64
(32, 8)

11. Python Matplotlib Library:-

The matplotlib is the popular library used for the data visualization as the pandas. This library is not related directly to ML.It comes if programmer want to visualize the pattern in data.
The library is 2D library and used for creating the graphs and plots.

Example:-
Import matplotlib.pyplot as plt
Import numpy as np
X=np.linespace (0, 10,100)
Plt.plot (x, x, label=’linear’)
Plt.legand ()
Plt.show()
Output:-

Python libraries for machine learning

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India