Implementation of the CNN algorithm for classification.
Code: loading libraries
|
Code: Load dataset
|
Output:

Code: Load dataset
|
Output:
RangeIndex: 569 entries , 0 to 568 Data columns (total 33 columns): id 569 non-null int64 diagnosis 569 non-null object radius_mean 569 non-null float64 texture_mean 569 non-null float64 perimeter_mean 569 non-null float64 area_mean 569 non-null float64 smoothness_mean 569 non-null float64 compactness_mean 569 non-null float64 concavity_mean 569 non-null float64 concave points_mean 569 non-null float64 symmetry_mean 569 non-null float64 texture-fractal_mean 569 non-radius_ null float 569 non-null float64 perimeter_se 569 non-null float64 area_se 569 non-null float64 smoothness_se 569 non-null float64 compactness_se 569 non-null float64 concavity_se 569 non-null float64 concave points_se 569 non-null float64 symmetry_se 569 non-nulldimension float64 non-null float64 radius_worst 569 non-null float64 texture_worst 569 non-null float64 perimeter_worst 569 non-null float64 area_worst 569 non-null float64 smoothness_worst 569 non-null float64 compactness_worst 569 non-null float64 concavity_worst 569 non-null float64 concavity_worst nullc points 569 non-null float64 concavity_worst nullc -null float64 symmetry_worst 569 non-null float64 fractal_dimension_worst 569 non-null float64 Unnamed: 32 0 non -null float64 dtypes: float64 (31), int64 (1), object (1) memory usage: 146.8+ KB
Code: we are dropping columns — "Id" and "Unnamed: 32" as they play no role in forecasting.
|
Exit:
(569, 31)
Convert diagnostic M and B values to numerical value
M (Malignant) = 1
B (Benign) = 0
|
Code:
|
Exit:
Code :
|
Output:
figure>
Code: input and output
|
Code: Separating data for training and testing
|
Code: Using Sklearn
|
Exit:
KNeighborsClassifier (algorithm = ’auto’ , leaf_size = 30, metric = ’minkowski’, metric_params = None, n_jobs = None, n_neighbors = 13, p = 2, weights =’ uniform’)
Code: forecast score
|
Exit:
0.9627659574468085
Code: doing cross validation
|
Code: classification error compared to k
|
Exit :
The optimal number of neighbors is 13