Best Python Libraries For Machine Learning - GeeksforGeeks
Best Python Libraries For Machine Learning - GeeksforGeeks
which they are able to learn from different kinds of data. A more general definition
given by Ar thur Samuel is – “Machine Learning is the field of study that gives
computers the ability to learn without being explicitly programmed.” They are typically
In the older days, people used to per form Machine Learning tasks by manually coding
all the algorithms and mathematical and statistical formula. This made the process
time consuming, tedious and inefficient. But in the modern days, it is become ver y
much easy and efficient compared to the olden days by various python libraries,
frameworks, and modules. Today, P ython is one of the most popular programming
languages for this task and it has replaced many languages in the industr y, one of the
reason is its vast collection of libraries. P ython libraries that used in Machine Learning
are:
Numpy
Scipy
Scikit-learn
Theano
TensorFlow
Keras
P yTorch
Pandas
Matplotlib
▲
Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python
Attention reader! Don’t stop learning now. Get hold of all the impor tant Machine
Numpy
NumP y is a ver y popular python librar y for large multi-dimensional array and matrix
par ticularly useful for linear algebra, Fourier transform, and random number
manipulation of Tensors.
P ython3
import numpy as np
Output :
219
[29 67]
[[19 22]
[43 50]]
SciP y
▲
SciP y is a ver y popular librar y among Machine Learning enthusiasts as it contains
different modules for optimization, linear algebra, integration and statistic s. There is a
difference between the SciP y librar y and the SciP y stack. The SciP y is one of the core
packages that make up the SciP y stack. SciP y is also ver y useful for image
manipulation.
P ython3
▲
Original image :
Tinted image :
▲
For more details refer to documentation.
Scikit-learn
built on top of two basic P ython libraries, viz., NumP y and SciP y. Scikit-learn suppor ts
most of the super vised and unsuper vised learning algorithms. Scikit-learn can also be
used for data-mining and data-analysis, which makes it a great tool who is star ting out
with ML.
▲
P ython3
# make predictions
expected = dataset.target
predicted = model.predict(dataset.data)
Output :
▲
[[50 0 0]
[ 0 50 0]
[ 0 0 50]]
Theano
We all know that Machine Learning is basically mathematic s and statistic s. Theano is a
popular python librar y that is used to define, evaluate and optimize mathematical
by optimizing the utilization of CPU and GPU. It is extensively used for unit-testing and
power ful librar y that has been used in large-scale computationally intensive scientific
projects for a long time but is simple and approachable enough to be used by
P ython3
Output :
array([[0.5, 0.73105858],
[0.26894142, 0.11920292]])
TensorFlow
TensorFlow is a ver y popular open-source librar y for high per formance numerical
computation developed by the Google Brain team in Google. A s the name suggests,
Tensor flow is a framework that involves defining and running computations involving
tensors. It can train and run deep neural networks that can be used to develop several
AI applications. TensorFlow is widely used in the field of deep learning research and
application.
▲
P ython3
# import `tensorflow`
import tensorflow as tf
# Multiply
result = tf.multiply(x1, x2)
Output :
[ 5 12 21 32]
Keras
▲
Keras is a ver y popular Machine Learning librar y for P ython. It is a high-level neural
networks API capable of running on top of TensorFlow, CNTK, or Theano. It can run
seamlessly on both CPU and GPU. Keras makes it really for ML beginners to build and
design a Neural Network. One of the best thing about Keras is that it allows for easy
P yTorch
▲
P yTorch is a popular open-source Machine Learning librar y for P ython based on Torch,
wrapper in Lua. It has an extensive choice of tools and libraries that suppor ts on
allows developers to per form computations on Tensors with GPU acceleration and
P ython3
import torch
dtype = torch.float
device = torch.device("cpu")
# device = torch.device("cuda:0") Uncomment this to run on GPU
learning_rate = 1e-6
for t in range(500):
# Forward pass: compute predicted y
h = x.mm(w1)
h_relu = h.clamp(min = 0)
y_pred = h_relu.mm(w2)
Output :
0 47168344.0
1 46385584.0
2 43153576.0
...
...
...
497 3.987660602433607e-05
498 3.945609932998195e-05
499 3.897604619851336e-05
Pandas
Pandas is a popular P ython librar y for data analysis. It is not directly related to
Machine Learning. A s we know that the dataset must be prepared before training. In
▲
this case, Pandas comes handy as it was developed specifically for data extraction and
preparation. It provides high-level data structures and wide variety tools for data
analysis. It provides many inbuilt methods for groping, combining and filtering data.
P ython3
# importing pandas as pd
import pandas as pd
data_table = pd.DataFrame(data)
print(data_table)
Output :
▲
Matplotlib
Matplotlib is a ver y popular P ython librar y for data visualization. Like Pandas, it is not
programmer wants to visualize the patterns in the data. It is a 2D plotting librar y used
for creating 2D graphs and plots. A module named pyplot makes it easy for
programmers for plotting as it provides features to control line styles, font proper ties,
formatting axes, etc. It provides various kinds of graphs and plots for data
P ython3
# Add a legend
plt.legend()
▲
Output :
Like 0
Previous Next
▲
Top 10 Javascript Libraries for
02 Machine Learning and Data 7 Best R Packages for Machine
06
Science Learning
14, Dec 20 22, Nov 20
Ar ticle Contributed By :
Rahul_Roy
@Rahul_Roy
▲
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
Company Learn
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Copyright Policy Video Tutorials