AI/ML python modules
AI/ML python modules
Objective: Learn basic Python libraries and syntax relevant for ML.
Machine learning has revolutionized the way we approach data-driven problems, enabling
computers to learn from data and make predictions or decisions without explicit
programming. Python, with its rich ecosystem of libraries and tools, has become the de facto
language for implementing machine learning algorithms.
cd path_to_location
mkdir FolderName
Step 2: Now in which ever directory you are, this line below will create a virtualenv there,
and here also you can name it anything.
python -m venv myenv
You can explicitly specify your path too. Similarly like Linux you can deactivate it like
deactivate
Reference:https://www.geeksforgeeks.org/creating-python-virtual-environment-windows-
linux/?ref=ml_lbp
Python matplotlib
Matplotlib is a powerful and versatile open-source plotting library for Python, designed to
help users visualize data in a variety of formats.
pip install matplotlib
Key Features of Matplotlib
Versatile Plotting: Create a wide variety of visualizations, including line plots,
scatter plots, bar charts, and histograms.
Extensive Customization: Control every aspect of your plots, from colors and
markers to labels and annotations.
Seamless Integration with NumPy: Effortlessly plot data arrays directly,
enhancing data manipulation capabilities.
High-Quality Graphics: Generate publication-ready plots with precise control over
aesthetics.
Cross-Platform Compatibility: Use Matplotlib on Windows, macOS, and Linux
without issues.
Interactive Visualizations: Engage with your data dynamically through interactive
plotting features.
Example of a Plot in Matplotlib : Let’s create a simple line plot using Matplotlib,
showcasing the ease with which you can visualize data.
Output:
How you implement python matplotlib in your virtual environment:
import matplotlib.pyplot as plt
Run python in your virtual environment then write your code:
The second way to use Matplotlib in your virtual environment is to write your code in a
notebook, save it with a .py extension, then activate your virtual environment and run the
file by typing python filename.py.
Different Types of Plots in Matplotlib
Matplotlib offers a wide range of plot types to suit various data visualization needs. Here
are some of the most commonly used types of plots in Matplotlib:
1. Line Graph
2. Bar Chart
3. Histogram
4. Scatter Plot
5. Pie Chart
6. 3D Plot
Outout:
In this example, a dictionary named data is created with keys representing column names
(Name, Age) and values as lists containing the respective data. pd.DataFrame() function
is then used to convert this dictionary into a DataFrame, which is stored in the variable df.
2. Reading CSV Files
CSV (Comma Separated Values) files are a common format for storing large datasets in
plain text. The Pandas library in Python provides, read_csv() function, to load these files
into a DataFrame. For our example we will use people.csv.
Output:
Output:
3. Dropping Columns from Data
Let’s drop a column from the data. We will use the drop function from the pandas. We
will keep axis = 1 for columns.
Output:
4. Dropping Rows from Data
Let’s try dropping a row from the dataset, for this, we will use drop function. We will
keep axis=0.
Output: