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()

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)
1st Edition
ISBN:9781305657458
Author:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Chapter6: Computing Components: Processors, Memory, The Cloud, And More
Section: Chapter Questions
Problem 16SG
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.
Recommended textbooks for you
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning
Principles of Information Systems (MindTap Course…
Principles of Information Systems (MindTap Course…
Computer Science
ISBN:
9781285867168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Fundamentals of Information Systems
Fundamentals of Information Systems
Computer Science
ISBN:
9781305082168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning
Fundamentals of Information Systems
Fundamentals of Information Systems
Computer Science
ISBN:
9781337097536
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning