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()
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()
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6f56d031-b647-4796-9490-6bff54b90583%2Fa28a51a0-f4e9-4339-ba90-f4326a65b9a8%2F2bqoya8_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Enhanced Discovering Computers 2017 (Shelly Cashm…](https://www.bartleby.com/isbn_cover_images/9781305657458/9781305657458_smallCoverImage.gif)
![Principles of Information Systems (MindTap Course…](https://www.bartleby.com/isbn_cover_images/9781285867168/9781285867168_smallCoverImage.gif)
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
![Enhanced Discovering Computers 2017 (Shelly Cashm…](https://www.bartleby.com/isbn_cover_images/9781305657458/9781305657458_smallCoverImage.gif)
![Principles of Information Systems (MindTap Course…](https://www.bartleby.com/isbn_cover_images/9781285867168/9781285867168_smallCoverImage.gif)
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
![Fundamentals of Information Systems](https://www.bartleby.com/isbn_cover_images/9781305082168/9781305082168_smallCoverImage.gif)
![Fundamentals of Information Systems](https://www.bartleby.com/isbn_cover_images/9781337097536/9781337097536_smallCoverImage.gif)