0% found this document useful (0 votes)
14 views4 pages

Best Python Libraries For Machine Learning

The document discusses essential Python libraries for Machine Learning, including NumPy for numerical computations, Pandas for data preparation, Matplotlib for data visualization, and SciPy for optimization and image manipulation. Each library is briefly described with examples demonstrating their functionalities. These libraries streamline the development process in Machine Learning by providing necessary tools for data handling and analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Best Python Libraries For Machine Learning

The document discusses essential Python libraries for Machine Learning, including NumPy for numerical computations, Pandas for data preparation, Matplotlib for data visualization, and SciPy for optimization and image manipulation. Each library is briefly described with examples demonstrating their functionalities. These libraries streamline the development process in Machine Learning by providing necessary tools for data handling and analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

best Python libraries for Machine Learning that streamline

development:
1. Numpy
NumPy is a very popular python library for large multi-
dimensional array and matrix processing, with the help of a large
collection of high-level mathematical functions. It is very useful
for fundamental scientific computations in Machine Learning. It
is particularly useful for linear algebra, Fourier transform, and
random number capabilities. High-end libraries like TensorFlow
uses NumPy internally for manipulation of Tensors.
Example: Linear Algebra Operations

import numpy as np
# Create a feature matrix (X) and target vector (y)
X = [Link]([[1, 2], [3, 4], [5, 6]])
y = [Link]([1, 2, 3])

# Calculate the mean of each feature


mean = [Link](X, axis=0)
print("Mean of features:", mean)
Output:
Mean of features: [3. 4.]
2. Pandas
Pandas is a popular Python library for data analysis. It is not
directly related to Machine Learning. As 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
grouping, combining and filtering data.
Example: Data Cleaning and Preparation
import pandas as pd

# Create a DataFrame with missing values


data = {
'Country': ['Brazil', 'Russia', 'India', None],
'Population': [200.4, 143.5, None, 52.98]
}
df = [Link](data)

# Fill missing values


df['Population'].fillna(df['Population'].mean(), inplace=True)
print(df)
Output:
Country Population
0 Brazil 200.40
1 Russia 143.50
2 India 132.99
3 None 52.98
3. Matplotlib
Matplotlib is a very popular Python library for data visualization.
Like Pandas, it is not directly related to Machine Learning. It
particularly comes in handy when a programmer wants to
visualize the patterns in the data. It is a 2D plotting library 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
properties, formatting axes, etc.
 It provides various kinds of graphs and plots for data
visualization, viz., histogram, error charts, bar chats, etc,
Example: Creating a linear Plot
# Python program using Matplotlib
# for forming a linear plot

# importing the necessary packages and modules


import [Link] as plt
import numpy as np

# Prepare the data


x = [Link](0, 10, 100)

# Plot the data


[Link](x, x, label ='linear')

# Add a legend
[Link]()

# Show the plot


[Link]()

Output:

Output

4. SciPy
SciPy is a very popular library among Machine Learning
enthusiasts as it contains different modules for optimization,
linear algebra, integration and statistics. There is a difference
between the SciPy library and the SciPy stack. The SciPy is one
of the core packages that make up the SciPy stack. SciPy is
also very useful for image manipulation.
Example: Image Manipulation
Image Manipulation
# Python script using Scipy
# for image manipulation

from [Link] import imread, imsave, imresize

# Read a JPEG image into a numpy array


img = imread('D:/Programs / [Link]') # path of the image
print([Link], [Link])

# Tinting the image


img_tint = img * [1, 0.45, 0.3]

# Saving the tinted image


imsave('D:/Programs / cat_tinted.jpg', img_tint)

# Resizing the tinted image to be 300 x 300 pixels


img_tint_resize = imresize(img_tint, (300, 300))

# Saving the resized tinted image


imsave('D:/Programs / cat_tinted_resized.jpg',
img_tint_resize)

You might also like