TODO 3 Complete the TODO by filling in the code for plotting the sepal length and width features against each other for each iris flowers. The resulting plot should match the below plot image. Using all the setosa data samples ONLY, index the 'sepal length' feature from the iris_df. Store the output into setosa_sepal_length Hint: Recall .loc[] requires two inputs, one for rows and one for columns as follows: .loc[rows, columns]. The rows we need to access are stored in setosa_locs! Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the setosa data samples. Store the output into setosa_sepal_width Using TODO 3.1 as an example, index the 'sepal length' feature from the iris_df for all the versicolor data samples. Store the output into versicolor_sepal_length Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the versicolor data samples. Store the output into versicolor_sepal_width Using TODO 3.1 as an example, index the 'sepal length' feature from the iris_df for all the virginica data samples. Store the output into virginica_sepal_length Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the virginica data samples. Store the output into virginica_sepal_width Plot the setosa sepal features we just extracted using plt.scatter() docs. Make sure setosa_sepal_length is plotted on the x-axis and setosa_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments: label='setosa' which will allow the legend to label each data sample plotted as the correct class. Plot the versicolor sepal features we just extracted using plt.scatter(). Make sure versicolor_sepal_length is plotted on the x-axis and versicolor_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments: label='versicolor' which will allow the legend to label each data sample plotted as the correct class. Plot the virginica sepal features we just extracted using plt.scatter(). Make sure virginica_sepal_length is plotted on the x-axis and virginica_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments: label='virginica' which will allow the legend to label each data sample plotted as the correct class. def plot_sepal_length_width(): # TODO 3.1 setosa_sepal_length = # TODO 3.2 setosa_sepal_width = # TODO 3.3 versicolor_sepal_length = # TODO 3.4 versicolor_sepal_width = # TODO 3.5 virginica_sepal_length = # TODO 3.6 virginica_sepal_width = # Find min and max x-y coordiantes and add some buffer space for plotting (i.e., +- .5) x_min = iris_df.loc[:, 'sepal length'].min() - .5 x_max = iris_df.loc[:, 'sepal length'].max() + .5 y_min = iris_df.loc[:, 'sepal width'].min() - .5 y_max = iris_df.loc[:, 'sepal width'].max() + .5 # Set figure size for each plot plt.figure(figsize=(6,6)) # TODO 3.7 # TODO 3.8 # TODO 3.9 # Set plot settings plt.xlabel('Sepal length') plt.ylabel('Sepal width') plt.xlim(x_min, x_max) plt.ylim(y_min, y_max) plt.legend() # Plots legend plt.show() todo_check([ (np.all(setosa_sepal_length.values.flatten()[:3] == [5.1, 4.9, 4.7]), "'setosa_sepal_length' contains incorrect values!"), (np.all(setosa_sepal_width.values.flatten()[:3] == [3.5, 3. , 3.2]), "'setosa_sepal_width' contains incorrect values!"), (np.all(versicolor_sepal_length.values.flatten()[:3] == [7. , 6.4, 6.9]),"'versicolor_sepal_length' contains incorrect values!"), (np.all(versicolor_sepal_width.values.flatten()[:3] == [3.2, 3.2, 3.1]),"'versicolor_sepal_width' contains incorrect values!"), (np.all(virginica_sepal_length.values.flatten()[:3] == [6.3, 5.8, 7.1]),"'virginica_sepal_length' contains incorrect values!"), (np.all(virginica_sepal_width.values.flatten()[:3] == [3.3, 2.7, 3.]),"'virginica_sepal_width' contains incorrect values!"), ]) plot_sepal_length_width()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

TODO 3

Complete the TODO by filling in the code for plotting the sepal length and width features against each other for each iris flowers. The resulting plot should match the below plot image.

  1. Using all the setosa data samples ONLY, index the 'sepal length' feature from the iris_df. Store the output into setosa_sepal_length

    1. Hint: Recall .loc[] requires two inputs, one for rows and one for columns as follows: .loc[rows, columns]. The rows we need to access are stored in setosa_locs!
  2. Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the setosa data samples. Store the output into setosa_sepal_width

  3. Using TODO 3.1 as an example, index the 'sepal length' feature from the iris_df for all the versicolor data samples. Store the output into versicolor_sepal_length

  4. Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the versicolor data samples. Store the output into versicolor_sepal_width

  5. Using TODO 3.1 as an example, index the 'sepal length' feature from the iris_df for all the virginica data samples. Store the output into virginica_sepal_length

  6. Using TODO 3.1 as an example, index the 'sepal width' feature from the iris_df for all the virginica data samples. Store the output into virginica_sepal_width

  7. Plot the setosa sepal features we just extracted using plt.scatter() docs. Make sure setosa_sepal_length is plotted on the x-axis and setosa_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments:

    1. label='setosa' which will allow the legend to label each data sample plotted as the correct class.
  8. Plot the versicolor sepal features we just extracted using plt.scatter(). Make sure versicolor_sepal_length is plotted on the x-axis and versicolor_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments:

    1. label='versicolor' which will allow the legend to label each data sample plotted as the correct class.
  9. Plot the virginica sepal features we just extracted using plt.scatter(). Make sure virginica_sepal_length is plotted on the x-axis and virginica_sepal_width is plotted on the y-axis. Additionally, pass the following keyword arguments:

    1. label='virginica' which will allow the legend to label each data sample plotted as the correct class.

def plot_sepal_length_width():    
    # TODO 3.1
    setosa_sepal_length = 
    # TODO 3.2
    setosa_sepal_width = 

    # TODO 3.3
    versicolor_sepal_length = 
    # TODO 3.4
    versicolor_sepal_width =

    # TODO 3.5
    virginica_sepal_length = 
    # TODO 3.6
    virginica_sepal_width =

    # Find min and max x-y coordiantes and add some buffer space for plotting (i.e., +- .5)
    x_min = iris_df.loc[:, 'sepal length'].min() - .5
    x_max = iris_df.loc[:, 'sepal length'].max() + .5
    y_min = iris_df.loc[:, 'sepal width'].min() - .5
    y_max = iris_df.loc[:, 'sepal width'].max() + .5

    # Set figure size for each plot
    plt.figure(figsize=(6,6))

    # TODO 3.7
    
    # TODO 3.8
    
    # TODO 3.9
    

    # Set plot settings
    plt.xlabel('Sepal length')
    plt.ylabel('Sepal width')
    plt.xlim(x_min, x_max)
    plt.ylim(y_min, y_max)
    plt.legend() # Plots legend
    plt.show()

    todo_check([
        (np.all(setosa_sepal_length.values.flatten()[:3] == [5.1, 4.9, 4.7]), "'setosa_sepal_length' contains incorrect values!"),
        (np.all(setosa_sepal_width.values.flatten()[:3] == [3.5, 3. , 3.2]), "'setosa_sepal_width' contains incorrect values!"),
        (np.all(versicolor_sepal_length.values.flatten()[:3] == [7. , 6.4, 6.9]),"'versicolor_sepal_length' contains incorrect values!"),
        (np.all(versicolor_sepal_width.values.flatten()[:3] == [3.2, 3.2, 3.1]),"'versicolor_sepal_width' contains incorrect values!"),
        (np.all(virginica_sepal_length.values.flatten()[:3] == [6.3, 5.8, 7.1]),"'virginica_sepal_length' contains incorrect values!"),
        (np.all(virginica_sepal_width.values.flatten()[:3] == [3.3, 2.7, 3.]),"'virginica_sepal_width' contains incorrect values!"),
    ])
    
plot_sepal_length_width()

Sepal width
4.5
4.0
3.5
3.0
2.5
2.0
15
4
5
●****
*****
6
Sepal length
7
setosa
versicolor
virginica
8
Transcribed Image Text:Sepal width 4.5 4.0 3.5 3.0 2.5 2.0 15 4 5 ●**** ***** 6 Sepal length 7 setosa versicolor virginica 8
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Image Element
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education