<jupyter_start><jupyter_text>**Keras** **Flow of Code** 1. Creating a model.2. Defining Architecture.3. Compile the model.4. Fit the model.5. Evaluaute the model. **Step 1** : Load Data<jupyter_code>from sklearn import datasets
cancer = datasets.load_breast_cancer()
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(cancer.data, cancer.target, test_size = 0.2, random_state = 0)

from sklearn.preprocessing import StandardScaler

sc = StandardScaler()
x_train = sc.fit_transform(x_train)
x_test = sc.transform(x_test)<jupyter_output><empty_output><jupyter_text>**Step 2** : Define Keras ModelCurrently we will use Dense layers. While defining the model, we need to know the number of units we want to keep in each layer, their activation function, and input dimensions for the first layer.<jupyter_code>from keras.models import Sequential
from keras.layers import Dense
# Creating a Model
model = Sequential()
layer1 = Dense(units=32, activation = 'relu', input_dim = 30)
model.add(layer1)
model.add(Dense(units=16, activation = 'relu'))
model.add(Dense(units=1, activation = 'sigmoid'))<jupyter_output><empty_output><jupyter_text>**Step 3** : Compile the ModelHere, we define the optimizer we want to use, along with the loss funtion and metrics.<jupyter_code>model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>**Step 4** : Fit the Model<jupyter_code>model.fit(x_train, y_train, epochs=20, batch_size = 50, validation_data=(x_test, y_test))<jupyter_output>Epoch 1/20
10/10 [==============================] - 1s 52ms/step - loss: 0.6454 - accuracy: 0.6503 - val_loss: 0.5250 - val_accuracy: 0.8509
Epoch 2/20
10/10 [==============================] - 0s 5ms/step - loss: 0.5133 - accuracy: 0.8480 - val_loss: 0.4218 - val_accuracy: 0.9035
Epoch 3/20
10/10 [==============================] - 0s 6ms/step - loss: 0.4052 - accuracy: 0.9337 - val_loss: 0.3519 - val_accuracy: 0.9035
Epoch 4/20
10/10 [==============================] - 0s 6ms/step - loss: 0.3410 - accuracy: 0.9419 - val_loss: 0.2990 - val_accuracy: 0.9123
Epoch 5/20
10/10 [==============================] - 0s 19ms/step - loss: 0.2850 - accuracy: 0.9436 - val_loss: 0.2575 - val_accuracy: 0.9211
Epoch 6/20
10/10 [==============================] - 0s 6ms/step - loss: 0.2423 - accuracy: 0.9511 - val_loss: 0.2246 - val_accuracy: 0.9211
Epoch 7/20
10/10 [==============================] - 0s 6ms/step - loss: 0.2027 - accuracy: 0.9516 - val_loss: 0.1994 - val_accuracy: 0.9211
Epoch 8/20
10/10 [[...]<jupyter_text>**Step 5** : Evaluating the Model<jupyter_code>predictions = model.predict(x_test)
score = model.evaluate(x_test, y_test)
score<jupyter_output>4/4 [==============================] - 0s 2ms/step - loss: 0.0861 - accuracy: 0.9737
{'fraction_non_alphanumeric': 0.205363443895554, 'fraction_numerical': 0.08892025405786874, 'mean_word_length': 5.272123893805309, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '603775', 'license': 'MIT', 'n_tokens_mistral': 1181, 'n_tokens_neox': 993, 'n_words': 255, 'path': 'Keras/0000000000000482[1].ipynb', 'repo_name': 'VithalGulati/Machine_Learning', 'size': '2834'}