02/01/2025, 12:42 Untitled10
Creating a Line chart or Plotting lines using
matplotlib
In [4]: import [Link] as plt
import numpy as np
import pandas as pd
In [5]: [Link](figsize=(5,5))
[Link]([1,2,3,4], [1,4,9,16])
[Link]("my first Graph")
[Link]("X_numbers")
[Link]("Y_numbers")
[Link]()
In [ ]:
Write code to change the horizontal
histogram type to step filled and it should
be cumulative.
localhost:8888/nbconvert/html/[Link]?download=false 1/4
02/01/2025, 12:42 Untitled10
Creating Histogram To create histogram in python hist() function is used. The syntax of hist()
function is like this:
In [10]: import [Link] as m
english=[77,66,88,99,55,33,79,44,68,83]
maths=[56,78,89,40,65,90,80,47,82]
[Link]([english,maths], orientation='horizontal', histtype='stepfilled', cumulative=Tr
[Link]()
Write python code to create histogram
based on given data
English: 77,66,88,99,55,44,33,79,68,83 Hindi:
56,89,70,50,60,65,90,80,47,82
In [11]: import [Link] as m
english=[77,66,88,99,55,44,33,79,68,83]
maths=[56,89,70,50,60,65,90,80,47,82]
[Link]([english,maths])
[Link]()
localhost:8888/nbconvert/html/[Link]?download=false 2/4
02/01/2025, 12:42 Untitled10
Creating a Confusion Matrix Confusion matrixes can be created by predictions made from a
logistic regression.
For now we will generate actual and predicted values by utilizing NumPy: import numpy
Next we will need to generate the numbers for "actual" and "predicted" values.
actual = [Link](1, 0.9, size = 1000) predicted = [Link](1,
0.9, size = 1000)
In order to create the confusion matrix we need to import metrics from the sklearn module.
from sklearn import metrics
Once metrics is imported we can use the confusion matrix function on our actual and predicted
values.
confusion_matrix = metrics.confusion_matrix(actual, predicted)
To create a more interpretable visual display we need to convert the table into a confusion
matrix display.
cm_display = [Link](confusion_matrix = confusion_matrix,
display_labels = [0, 1])
localhost:8888/nbconvert/html/[Link]?download=false 3/4
02/01/2025, 12:42 Untitled10
Vizualizing the display requires that we import pyplot from matplotlib.
import [Link] as plt
Finally to display the plot we can use the functions plot() and show() from pyplot.
cm_display.plot() [Link]()
In [12]: import [Link] as plt
import numpy
from sklearn import metrics
actual = [Link](1,.9,size = 1000)
predicted = [Link](1,.9,size = 1000)
confusion_matrix = metrics.confusion_matrix(actual, predicted)
cm_display = [Link](confusion_matrix = confusion_matrix, displ
cm_display.plot()
[Link]()
In [ ]:
localhost:8888/nbconvert/html/[Link]?download=false 4/4