Python Lesson 6 Classes, Objects, Dictionaries, Modules, Libraries, and Graphing Techniques
Python Lesson 6 Classes, Objects, Dictionaries, Modules, Libraries, and Graphing Techniques
del phonebook['John’]
phonebook.pop('John’)
import keyword
Print(keyword.kwlist)
Python Libraries
import numpy as np
import matplotlib.pyplot as plt
# Create 1000 evenly spaced values from 0 to 100
t = np.linspace(0, 100, 1000)
# Plot t vs t^2 (quadratic function)
plt.plot(t, t**2)
# Display the plot
plt.show()
Example: Graphing with Matplotlib
1.import numpy as np:
This imports the NumPy library and assigns it the alias np for
ease of use. NumPy is widely used for working with arrays and
numerical data.
4.plt.plot(t, t**2):
plt.plot() is the function that plots a graph.
t is the array of x-values (from 0 to 100).
t**2 is the array of y-values, where each value of t
is squared. So, the graph will plot the square of t
on the y-axis.
5.plt.show():
This displays the graph to the user. Without calling
this, the graph won't appear.
Example: Machine Learning with
Scikit-learn
Here is an example of using Scikit-learn for machine
learning.
The Iris dataset is one of the most famous datasets
used in machine learning. Adding a brief description
could help clarify this for beginners.
2.Iris = datasets.load_iris():
This line loads the Iris dataset, which contains information about
150 iris flowers, categorized into 3 species: Setosa, Versicolor,
and Virginica.
The dataset includes 4 features for each flower: