<jupyter_start><jupyter_text>Diagnose whether the patient has breast cancer using the features(attributes)provided.**What data is available?**Features( attributes) and corresponding labels( diagnosis) as a csv file. 1.   Features are computed from a digitized image offine needle aspirate( FNA) of a breast mass a2.   class problem: B-benign or M-malignant.**Strategy:** Use deep learning to train a model using features as input and labeled diagnosis (B or M) as output on the training  data. Then, evaluate the accuracy on the testing data.<jupyter_code>import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
df = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/datasets/data.csv")
print(df.describe().T)
print(df.isnull().sum())
df = df.drop('Unnamed: 32', axis=1 )
print(df.describe().T)
print(df.isnull().sum())
#Rename Dataset to Label to make it easy to understand 
df = df.rename(columns={'diagnosis': 'label'})
print(df.dtypes)
# Understand the data
sns.countplot(x='label', data=df) # M - malignant, B - benign
####### Replace categorical values with numbers########
print("Distribution of data: ", df['label'].value_counts())

#Define the dependent variable that needs to be predicted (labels)
y = df["label"].values
print("Labels before encoding are: ", np.unique(y))

# Encoding categorical data from text (B and M) to integers (0 and 1)
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()
Y = labelencoder.fit_transform(y) # M=1 and B=0
print("Labels after encoding are: ", np.unique(Y))
#Define x and normalize / scale values

#Define the independent variables. Drop label and ID, and normalize other data
X = df.drop(labels = ["label", "id"], axis=1) 
print(X.describe().T) #Needs scaling
#Scale / normalize the values to bring them to similar range
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(X)
X = scaler.transform(X)
print(X)  #Scaled values
#Split data into train and test to verify accuracy after fitting the model. 
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.25, random_state=42)
print("Shape of training data is: ", X_train.shape)
print("Shape of testing data is: ", X_test.shape)
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
model = Sequential()
model.add(Dense(16, input_dim=30, activation='relu')) 
model.add(Dropout(0.2))
model.add(Dense(1)) 
model.add(Activation('sigmoid')) 
 
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

print(model.summary())
#Fit with no early stopping or other callbacks
history = model.fit(X_train, y_train, verbose=1, epochs=100, batch_size=64,
                    validation_data=(X_test, y_test))
#plot the training and validation accuracy and loss at each epoch
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(1, len(loss) + 1)
plt.plot(epochs, loss, 'y', label='Training loss')
plt.plot(epochs, val_loss, 'r', label='Validation loss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()


acc = history.history['accuracy']  #Use accuracy if acc doesn't work
val_acc = history.history['val_accuracy']  #Use val_accuracy if acc doesn't work
plt.plot(epochs, acc, 'y', label='Training acc')
plt.plot(epochs, val_acc, 'r', label='Validation acc')
plt.title('Training and validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.show()
# Predicting the Test set results
y_pred = model.predict(X_test)
y_pred = (y_pred > 0.5)

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

sns.heatmap(cm, annot=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12483711232733907, 'fraction_numerical': 0.00833984884023977, 'mean_word_length': 5.792920353982301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '109897', 'license': 'Unlicense', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1201, 'n_words': 398, 'path': 'Binary_classification_breast_cancer.ipynb', 'repo_name': 'jahidhasan299/jahidhasan299-Deep-Learning-With-7-Real-Projects', 'size': '3837'}