<jupyter_start><jupyter_text><jupyter_code>import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns 
from google.colab import files
uploaded = files.upload()
df = pd.read_csv('data.csv')
df.head(7)
df.shape

df.isna
#drop all column with missing value we will drop the last col 
df=df.dropna(axis=1)

#get the new number of rows and col with no missing value 
df.shape
#get the number of (M) malignant  cells and (B) bengin  cells 
df['diagnosis'].value_counts()
#visualization the count 
sns.countplot(df['diagnosis'],label=['count'])
#look the datatype colume to look wich data need to encoded 
df.dtypes
#encode the catogrical data  data preprocessing
from sklearn.preprocessing import LabelEncoder
labelencoder_y=LabelEncoder()
df.iloc[:,1]=labelencoder_y.fit_transform (df.iloc[:,1].values)
#the diagnosis will encode to 0 & 1 insted of M & B 
#The row below sho that real value of diagnosis 
##df.iloc[:,1].values
#To see the 0 and 1 of vaule with index the row below show that 
##df.iloc[:,1]




#create the pair plot
sns.pairplot (df.iloc[:,1:5])
#create the pair plot with diagnosis to determine m or b cases like  point the 1 cancer cells and 0 the belign cells
sns.pairplot (df.iloc[:,1:5],hue='diagnosis')
#print the new data after preprocessing the encoding diagnosis colum
df.head(5)
#get the corrletion of data colum to can easily classifiction 
df.iloc [:,1:12].corr()
#get the  of data colum  without corrletion 
##df.iloc [:,1:12]
#visultion the corrletion data  
plt.figure(figsize=(10,10))
sns.heatmap(df.iloc[:,1:12].corr(),annot=True)

#split the data into independet data X and dependent data Y dataset
X=df.iloc[:,1:31].values
Y=df.iloc[:,1].values
#Split the data into 75% traning data and 25%test data
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,y_test= train_test_split(X,Y,test_size=0.2,random_state=0)
#scale feutre  fitting the data for test and train data for indepedned data (X)
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
X_test=sc.fit_transform(X_test)
X_train=sc.fit_transform(X_train)
X_train


#create  multiple functions for model 
def models (X_train,Y_train):
  #logistic model 
  from sklearn.linear_model import LogisticRegression
  import sklearn.linear_model as sk

  log=sk.LogisticRegressionCV()
  log.fit(X_train,Y_train)
   
  #decsion tree model to classifier 

  #from sklearn.tree import DecisionTreeRegressor
  #tree=DecisionTreeClassifier(criteron='entropy',random_state=0)
  #tree.fit(X_train,Y_train)
#print the accuray of each model then choice the model with high accurcay
  print('[0]logisticRegressin training accuray:',log.score(X_train,Y_train))
  
  #print('[0]logisticRegressin training accuray:',tree.score(X_train,Y_train))
  return log

from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, Y_train)

# Predicting the Test set results
y_pred = classifier.predict(X_test)
#getting all of the models 
model= models(X_train, Y_train)

#using xgb model to classifier
#from xgboost import XGBClassifier
#xgb_classifier = XGBClassifier()
#xgb_classifier.fit(X_train,Y_train)
#print('[0]logisticRegressin training accuray:' ,xgb_classifier.score(X_train,Y_train))
#find the cinfusion matrix to find the accuracy
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score
cm = confusion_matrix(y_test,y_pred)
plt.title('Heatmap of Confusion Matrix', fontsize = 15)
sns.heatmap(cm, annot = True)
plt.show()
## Pickle for save the model
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score
import pickle
# save model
pickle.dump(models, open('breast_cancer_detector.pickle', 'wb'))
 
# show the accuracy
print('Accuracy of XGBoost model = ',accuracy_score(y_test, y_pred))

 
# load model
breast_cancer_detector_model = pickle.load(open('breast_cancer_detector.pickle', 'rb'))<jupyter_output>Accuracy of XGBoost model =  1.0
{'fraction_non_alphanumeric': 0.09577603143418467, 'fraction_numerical': 0.012278978388998035, 'mean_word_length': 5.152567975830816, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '107693', 'license': 'Apache-2.0', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1417, 'n_words': 408, 'path': 'Breast_cancer_detect_using_ml_.ipynb', 'repo_name': 'rujeenaal-zyoud/-breast-cancer-detection-using-ML', 'size': '4072'}