<jupyter_start><jupyter_text>**Dealing with missing values and categorical values**<jupyter_code>#to drop the columns
df.drop(['Unnamed: 32','id'],axis=1,inplace=True)
#dealing with categorical data
df['diagnosis'].mask(df['diagnosis'] == 'M', 1 , inplace=True)
df['diagnosis'].mask(df['diagnosis'] == 'B', 0 , inplace=True)
#to display fist five row of the data
df.head()
print("Cancer data set dimensions : {}".format(df.shape))
df.groupby('diagnosis').size()
#heatmap
# no null values
heat_map = sns.heatmap(df.isnull(), yticklabels = False, cbar = True, cmap = "PuRd")
plt.show()<jupyter_output><empty_output><jupyter_text>**Countplot**<jupyter_code>sns.countplot(data=df, x='diagnosis')
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 569 entries, 0 to 568
Data columns (total 31 columns):
 #   Column                   Non-Null Count  Dtype  
---  ------                   --------------  -----  
 0   diagnosis                569 non-null    object 
 1   radius_mean              569 non-null    float64
 2   texture_mean             569 non-null    float64
 3   perimeter_mean           569 non-null    float64
 4   area_mean                569 non-null    float64
 5   smoothness_mean          569 non-null    float64
 6   compactness_mean         569 non-null    float64
 7   concavity_mean           569 non-null    float64
 8   concave points_mean      569 non-null    float64
 9   symmetry_mean            569 non-null    float64
 10  fractal_dimension_mean   569 non-null    float64
 11  radius_se                569 non-null    float64
 12  texture_se               569 non-null    float64
 13  perimeter_se             569 non-null    float64
 14  area_se                  5[...]<jupyter_text>**Splitting the dataset train and test set**<jupyter_code># independent variables
X = df.drop('diagnosis',axis=1)

#dependent variables
Y = df.diagnosis
Y = Y.astype('float64')
Y
from sklearn.preprocessing import LabelEncoder

#creating the object
lb = LabelEncoder()
Y = lb.fit_transform(Y)
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 = 40)
from sklearn.preprocessing import StandardScaler

#creating object
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)<jupyter_output><empty_output><jupyter_text>**Creating the model of ANN**<jupyter_code>#importing keras
import keras
#importing sequential module
from keras.models import Sequential
#import dense module for hidden layers
from keras.layers import Dense
#importing activation functions
from keras.layers import LeakyReLU,PReLU,ELU
from keras.layers import Dropout
#creating model
ann = Sequential()

#first hidden layer
ann.add(Dense(units=9,kernel_initializer='he_uniform',activation='relu',input_dim=30))

#second hidden layer
ann.add(Dense(units=9,kernel_initializer='he_uniform',activation='relu'))

#last layer or output layer
ann.add(Dense(units=1,kernel_initializer='glorot_uniform',activation='sigmoid'))
#taking summary of layers
ann.summary()
#compiling the ANN
ann.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
#fitting the ANN to the training set
model = ann.fit(X_train, y_train, validation_split=0.33, batch_size=100, epochs=100)
#now testing for test data
predictions_ann = ann.predict(X_test)
predictions_ann = (predictions_ann>0.5)
predictions_ann<jupyter_output><empty_output><jupyter_text>**Predicting a single observation**<jupyter_code>#new prediction based on given input
new_input = [[17.99, 10.38, 122.8, 1001, 0.1184, 0.2776, 0.3001, 0.1471, 0.2419, 0.07871, 1.095, 0.9053, 8.589, 153.4, 0.006399, 0.04904, 0.05373, 0.01587, 0.03003, 0.006193, 25.38, 17.33, 184.6, 2019, 0.1622, 0.6656, 0.7119, 0.2654, 0.4601,0.1189]] #[['duration','credit_amount','installment_commitment','residence_since','age','existing_credits','num_dependents']]
new_output = ann.predict(new_input)
print(new_input, new_output)
if new_output == True:
  print("Malignant Diagnosis")
else:
  print("Benign Diagnosis")
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
cm = confusion_matrix(y_test,predictions_ann)
score = accuracy_score(y_test,predictions_ann)
print(cm)
print('score is:',score)
#creating heatmap of confussion matrix
plt.figure(figsize=[7,5])
sns.heatmap(cm,annot=True)
plt.show()<jupyter_output><empty_output><jupyter_text>**Graph plotting of accuracy and loss**<jupyter_code>#summarize history for accuracy
plt.plot(model.history['accuracy'])
plt.plot(model.history['val_accuracy'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
#summarize history for loss
plt.plot(model.history['loss'])
plt.plot(model.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12814323073828204, 'fraction_numerical': 0.05552202776101388, 'mean_word_length': 4.701834862385321, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '288173', 'license': 'MIT', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1686, 'n_words': 393, 'path': 'Breast_Cancer_Prediction_ANN.ipynb', 'repo_name': 'iamdhrutipatel/BreastTest', 'size': '4971'}