<jupyter_start><jupyter_text>**Breast Cancer Prediction**\This project predicts if the tumor is malignant or benign based on the risk factors.<jupyter_code>import pandas as pd 
import seaborn as sns 
import matplotlib.pyplot as plt
import numpy as np
from google.colab import files
uploaded = files.upload()
#importing our cancer dataset
dataset = pd.read_csv('cancer.csv',header=0)
dataset.head()
print("Cancer data set dimensions : {}".format(dataset.shape))
dataset.isnull().sum()
dataset.isna().sum()
dataset.drop("Unnamed: 32",axis=1,inplace=True)
dataset.drop("id",axis=1,inplace=True)
prediction_var = ['texture_mean','perimeter_mean','smoothness_mean','compactness_mean','symmetry_mean']
features_mean= list(dataset.columns[1:11])
features_se= list(dataset.columns[11:20])
features_worst=list(dataset.columns[21:31])
print(features_mean)
print("-----------------------------------")
print(features_se)
print("------------------------------------")
print(features_worst)
#Encoding categorical data values
dataset['diagnosis']=dataset['diagnosis'].map({'M':1,'B':0})
dataset.describe()
sns.countplot(x=dataset['diagnosis'],label="Count")
corr = dataset[features_mean].corr() # .corr is used for find corelation
plt.figure(figsize=(14,14))
sns.heatmap(corr, cbar = True,  square = True, annot=True, fmt= '.2f',annot_kws={'size': 15},
           xticklabels= features_mean, yticklabels= features_mean,
           cmap= 'coolwarm')
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
train, test = train_test_split(dataset, test_size = 0.25, random_state = 1)
X_train = train[prediction_var]# taking the training data input 
Y_train=train.diagnosis# This is output of our training data
# same we have to do for test
X_test= test[prediction_var] # taking test data inputs
Y_test =test.diagnosis   #output value of test dat
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
#Using Logistic Regression Algorithm to the Training Set
from sklearn.metrics import confusion_matrix
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("Logistic Regression\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using KNeighborsClassifier Method of neighbors class to use Nearest Neighbor algorithm
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nK Neighbors Classifier\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using SVC method of svm class to use Support Vector Machine Algorithm
from sklearn.svm import SVC
classifier = SVC(kernel = 'linear', random_state = 0)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nSupport Vector Machine (linear)\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using SVC method of svm class to use Kernel SVM Algorithm
from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nSupport Vector Machine (rbf)\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using GaussianNB method of naïve_bayes class to use Naïve Bayes Algorithm
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nGaussian Naive Bayesian\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using DecisionTreeClassifier of tree class to use Decision Tree Algorithm
from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nDecision Tree Classifier\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))

#Using RandomForestClassifier method of ensemble class to use Random Forest Classification algorithm
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)
classifier.fit(X_train, Y_train)
Y_pred = classifier.predict(X_test)
cm = confusion_matrix(Y_test, Y_pred)
print("\nRandom Forest Classifier\nConfusion matrix:")
print(cm)
print("Accuracy: ")
print((cm[0,0]+cm[1,1])/(cm[0,0]+cm[0,1]+cm[1,1]+cm[1,1]))<jupyter_output>Logistic Regression
Confusion matrix:
[[83  5]
 [ 8 47]]
Accuracy: 
0.7142857142857143

K Neighbors Classifier
Confusion matrix:
[[83  5]
 [ 8 47]]
Accuracy: 
0.7142857142857143

Support Vector Machine (linear)
Confusion matrix:
[[83  5]
 [ 7 48]]
Accuracy: 
0.7119565217391305

Support Vector Machine (rbf)
Confusion matrix:
[[84  4]
 [10 45]]
Accuracy: 
0.7247191011235955

Gaussian Naive Bayesian
Confusion matrix:
[[85  3]
 [ 8 47]]
Accuracy: 
0.7252747252747253

Decision Tree Classifier
Confusion matrix:
[[81  7]
 [10 45]]
Accuracy: 
0.7078651685393258

Random Forest Classifier
Confusion matrix:
[[84  4]
 [10 45]]
Accuracy: 
0.7247191011235955