check for mistakes and the reason why the code isn’t matching
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
Related questions
Question
I already solved I and II, I’m finding it hard matching the images in the question to the ones in my code in III, please check for mistakes and the reason why the code isn’t matching. PS this isn’t an assignment or graded work.
![In [11]:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import sklearn.
from sklearn.datasets import load_breast cancer
breast cancer -load_breast cancer (return_X_y True, as frame True)
a breast cancer [0]
b
breast cancer [1]
a['classes - b
In [12] cancer sklearn.datasets.load_breast cancer ()
Out [15]:
a pd. DataFrame (cancer ['data'],columns-cancer.feature_names)
a['typeofcancer'] cancer['target']
In [13]: print (a.shape)
#creaing a dataframe df
(569, 31).
In [14]: df=a.iloc[:, [0,2,3,-1]]
In [15]: df.head (2)
0
1
17
18
19
mean radius mean perimeter mean area typeofcancer
In [16]: df.iloc [[17,18,19,20,21],:]
Out [16]:
20
21
17.99
20.57
mean radius mean perimeter mean area typeofcancer
16.130
108.10
798.8
19.810
13.540
13.080
9.504
122.8
132.9
357
212
plt.tight_layout()
In [18]: asorted.typeofcancer.value_counts()
Out [18] 1
0
Name: typeofcancer, dtype: int64
100
130.00
75
87.46
85.63
60.34
In [17]: asorted = a.sort_values ('typeofcancer',ignore_index=True)
asorted;
50-
25
1001.0
1326.0
axsl.set_xlabel('mean radius')
axsl.set_ylabel('frequney')
1260.0
566.3
In [19]: f0, fl asorted.typeofcancer.value_counts()
fo, fl
Out [19]: (357, 212)
520.0
273.9
In [20]: fig, axs plt.subplots (figsize (10,2.5))
(0,0))
axs1 plt.subplot2grid (shape= (1, 3), loc
plt.subplot2grid (shape= (1, 3), loc
axs2
(0,1))
axs3 plt.subplot2grid (shape= (1, 3), loc= (0,2))
10
15
axs1.hist (a.iloc [0:f0, 0], edgecolor='r', fe='none', label='c0')
axs1.hist (a.iloc [f0:f0+f1l, 0], edgecolor='b', fe='none', label='c1')
0
0
axs1.legend()
axs2.scatter (a.iloc [0:f0, 2], a.iloc [0:f0, 0], label='c0(M)')
axs2.scatter (a.iloc [f0:f0+f1, 2], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs2.set_xlabel('mean perimeter')
axs2.set_ylabel('mean radius')
axs2.legend()
axs3.scatter (a.iloc [0:f0, 3), a.iloc [0:f0, 0], label='c0(M)')
axs3.scatter (a.iloc [f0:f0+f1, 3], a.iloc [f0:f0+f1, 0], label='cl(B)')
axs3.set_xlabel('mean area')
axs3.set_ylabel('mean radius')
axs3.legend()
20
0
0
Out [20]: <matplotlib.legend. Legend at 0x7fa5c12a0f70>
1
c0(M)
25 ● cl(B)
20
wor
15
10
50
100
mean perimeter
mean radius
1
25
1
150
..
25
10
● CO(M)
cl(B)
500 1000 1500 2000 2500
mean area](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2cd2d665-daee-46b8-ac4c-2b4cec66538a%2Fd4ab772a-04d6-4c44-a5a8-7f09ce29b6e2%2Ffnnwe2_processed.png&w=3840&q=75)
Transcribed Image Text:In [11]:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import sklearn.
from sklearn.datasets import load_breast cancer
breast cancer -load_breast cancer (return_X_y True, as frame True)
a breast cancer [0]
b
breast cancer [1]
a['classes - b
In [12] cancer sklearn.datasets.load_breast cancer ()
Out [15]:
a pd. DataFrame (cancer ['data'],columns-cancer.feature_names)
a['typeofcancer'] cancer['target']
In [13]: print (a.shape)
#creaing a dataframe df
(569, 31).
In [14]: df=a.iloc[:, [0,2,3,-1]]
In [15]: df.head (2)
0
1
17
18
19
mean radius mean perimeter mean area typeofcancer
In [16]: df.iloc [[17,18,19,20,21],:]
Out [16]:
20
21
17.99
20.57
mean radius mean perimeter mean area typeofcancer
16.130
108.10
798.8
19.810
13.540
13.080
9.504
122.8
132.9
357
212
plt.tight_layout()
In [18]: asorted.typeofcancer.value_counts()
Out [18] 1
0
Name: typeofcancer, dtype: int64
100
130.00
75
87.46
85.63
60.34
In [17]: asorted = a.sort_values ('typeofcancer',ignore_index=True)
asorted;
50-
25
1001.0
1326.0
axsl.set_xlabel('mean radius')
axsl.set_ylabel('frequney')
1260.0
566.3
In [19]: f0, fl asorted.typeofcancer.value_counts()
fo, fl
Out [19]: (357, 212)
520.0
273.9
In [20]: fig, axs plt.subplots (figsize (10,2.5))
(0,0))
axs1 plt.subplot2grid (shape= (1, 3), loc
plt.subplot2grid (shape= (1, 3), loc
axs2
(0,1))
axs3 plt.subplot2grid (shape= (1, 3), loc= (0,2))
10
15
axs1.hist (a.iloc [0:f0, 0], edgecolor='r', fe='none', label='c0')
axs1.hist (a.iloc [f0:f0+f1l, 0], edgecolor='b', fe='none', label='c1')
0
0
axs1.legend()
axs2.scatter (a.iloc [0:f0, 2], a.iloc [0:f0, 0], label='c0(M)')
axs2.scatter (a.iloc [f0:f0+f1, 2], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs2.set_xlabel('mean perimeter')
axs2.set_ylabel('mean radius')
axs2.legend()
axs3.scatter (a.iloc [0:f0, 3), a.iloc [0:f0, 0], label='c0(M)')
axs3.scatter (a.iloc [f0:f0+f1, 3], a.iloc [f0:f0+f1, 0], label='cl(B)')
axs3.set_xlabel('mean area')
axs3.set_ylabel('mean radius')
axs3.legend()
20
0
0
Out [20]: <matplotlib.legend. Legend at 0x7fa5c12a0f70>
1
c0(M)
25 ● cl(B)
20
wor
15
10
50
100
mean perimeter
mean radius
1
25
1
150
..
25
10
● CO(M)
cl(B)
500 1000 1500 2000 2500
mean area
![Create a dataframe variable 'a' with this dataset. This dataframe should have all the 569 instances,
30 features and the class of 569 instances as 0 (Malignant) or 1 (Benign). The column that contains
the classes should be labeled as 'typeofcancer'. Show the output of the following input:
In [13]:
▸a.shape
[Hints: the outputs should be same as below.
Out [13] (569, 31)
(b) Now create a dataframe variable 'df' by slicing dataframe 'a'. The new datafraeme 'df' should
have all the instances, their labels but with the following three features: mean radius, mean
perimeter and mean area. [Hints: use .iloc method to extract necessary columns from 'a']
(i) Show the first two rows.
[Hint: The output should be same as below.
Out [16]:
80
0
(ii) Show the rows with indexes 17, 18, 19, 20, 21.
60
1
40
mean radius mean perim
17.99
20.57
(iii) Suppose we want to explore the possibility of developing a machine learning model that can
diagnose a new patient's cancer condition as benign or malignant from the features in df.
20
As a first step, you want to do some graphical analysis. Write the code to generate the following
figure (Figure 1). Show screenshot of the code (input) and the figure (output) from your work. You
are free to choose your favorite data marker and color in your figure.
10
CO(M)
25
● c1(B)
20
OD07
15
10
50
150
100
mean perimeter
122.8
132.9
mean area typeofcancer
1001.0
1326.0
CO(Malignant)
c1(Benign)
0
0
15 20
mean radius
25
10
CO(M)
c1(B)
500
1000 1500 2000 2500
mean area
Figure 1: From left of right: histogram of 'mean radius' data for each class, scatter plot of 'mean
radius' versus 'mean perimeter', scatter plot of 'mean radius' versus 'mean area'.
(iv) Briefly describe what each of the subplots in Figure 1 reveal about the data.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2cd2d665-daee-46b8-ac4c-2b4cec66538a%2Fd4ab772a-04d6-4c44-a5a8-7f09ce29b6e2%2F0trl73_processed.png&w=3840&q=75)
Transcribed Image Text:Create a dataframe variable 'a' with this dataset. This dataframe should have all the 569 instances,
30 features and the class of 569 instances as 0 (Malignant) or 1 (Benign). The column that contains
the classes should be labeled as 'typeofcancer'. Show the output of the following input:
In [13]:
▸a.shape
[Hints: the outputs should be same as below.
Out [13] (569, 31)
(b) Now create a dataframe variable 'df' by slicing dataframe 'a'. The new datafraeme 'df' should
have all the instances, their labels but with the following three features: mean radius, mean
perimeter and mean area. [Hints: use .iloc method to extract necessary columns from 'a']
(i) Show the first two rows.
[Hint: The output should be same as below.
Out [16]:
80
0
(ii) Show the rows with indexes 17, 18, 19, 20, 21.
60
1
40
mean radius mean perim
17.99
20.57
(iii) Suppose we want to explore the possibility of developing a machine learning model that can
diagnose a new patient's cancer condition as benign or malignant from the features in df.
20
As a first step, you want to do some graphical analysis. Write the code to generate the following
figure (Figure 1). Show screenshot of the code (input) and the figure (output) from your work. You
are free to choose your favorite data marker and color in your figure.
10
CO(M)
25
● c1(B)
20
OD07
15
10
50
150
100
mean perimeter
122.8
132.9
mean area typeofcancer
1001.0
1326.0
CO(Malignant)
c1(Benign)
0
0
15 20
mean radius
25
10
CO(M)
c1(B)
500
1000 1500 2000 2500
mean area
Figure 1: From left of right: histogram of 'mean radius' data for each class, scatter plot of 'mean
radius' versus 'mean perimeter', scatter plot of 'mean radius' versus 'mean area'.
(iv) Briefly describe what each of the subplots in Figure 1 reveal about the data.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
DIDNT WORK
![asorted;
In [18]: asorted.typeofcancer.value_counts()
Out [18] 1
0
Name: typeofcancer, dtype: int64
357
212
In [19]: f0,f1 = asorted.typeofcancer.value_counts()
f0, f1
Out [19]: (357, 212)
In [ ]:
In [24]: fig, axs
= plt.subplots (figsize = (10,2.5))
axs1 = plt.subplot2grid (shape= (1, 3), loc = (0,0))
axs2 = plt.subplot2grid (shape= (1, 3), loc = (0,1))
axs3 = plt.subplot2grid (shape= (1, 3), loc = (0,2))
plt.tight_layout()
axs1.hist (a.iloc [0:f0, 0], edgecolor='r', fc='none', label='c0')
axs1.hist (a.iloc [f0:f0+f1, 0], edgecolor='b', fc='none', label='c1')
axs1.set_xlabel('mean radius')
axsl.set_ylabel('frequncy')
axs1.legend()
ax2.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M) ')
axs2.scatter (a.iloc [f0:f0+f1, 2], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs2.set_xlabel('mean perimeter')
axs2.set_ylabel('mean radius')
axs2.legend()
ax3.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M)')
axs3.scatter (a.iloc [f0:f0+f1, 3], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs3.set_xlabel('mean area')
axs3.set_ylabel('mean radius')
axs3.legend()
Input In [24]
ax2.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M)')
SyntaxError: invalid syntax](https://content.bartleby.com/qna-images/question/2cd2d665-daee-46b8-ac4c-2b4cec66538a/d1cc7e14-17ed-400d-8616-d3b4d0a87897/lzx5ntm_thumbnail.png)
Transcribed Image Text:asorted;
In [18]: asorted.typeofcancer.value_counts()
Out [18] 1
0
Name: typeofcancer, dtype: int64
357
212
In [19]: f0,f1 = asorted.typeofcancer.value_counts()
f0, f1
Out [19]: (357, 212)
In [ ]:
In [24]: fig, axs
= plt.subplots (figsize = (10,2.5))
axs1 = plt.subplot2grid (shape= (1, 3), loc = (0,0))
axs2 = plt.subplot2grid (shape= (1, 3), loc = (0,1))
axs3 = plt.subplot2grid (shape= (1, 3), loc = (0,2))
plt.tight_layout()
axs1.hist (a.iloc [0:f0, 0], edgecolor='r', fc='none', label='c0')
axs1.hist (a.iloc [f0:f0+f1, 0], edgecolor='b', fc='none', label='c1')
axs1.set_xlabel('mean radius')
axsl.set_ylabel('frequncy')
axs1.legend()
ax2.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M) ')
axs2.scatter (a.iloc [f0:f0+f1, 2], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs2.set_xlabel('mean perimeter')
axs2.set_ylabel('mean radius')
axs2.legend()
ax3.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M)')
axs3.scatter (a.iloc [f0:f0+f1, 3], a.iloc [f0:f0+f1, 0], label='c1(B)')
axs3.set_xlabel('mean area')
axs3.set_ylabel('mean radius')
axs3.legend()
Input In [24]
ax2.scatter (1.iloc [0:f0, 5], a.iloc [0:f0, 0], label='c0 (M)')
SyntaxError: invalid syntax
Solution
Knowledge Booster
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

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education