<jupyter_start><jupyter_text>Today, I will be making a Heart Disease Prediction machine based on data from: https://www.kaggle.com/ronitf/heart-disease-uci/version/1 \Libraries:* Pandas (to read the data)* Tensorflow (for modelling)* Math because 9+10=212+2=3-1=4quikmafs<jupyter_code>import pandas as pd
import tensorflow as tf
import tensorflow.keras
import tensorflow.keras.layers
print("Imported!")<jupyter_output>Imported!<jupyter_text>Importing data and cleaning it<jupyter_code>ds = pd.read_csv('https://raw.githubusercontent.com/stonkmem/Heart-Failure-Predictor/main/heart.csv')
ds = ds.sample(frac=1) #This shuffles the data
x_p = ds[['age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang', 'oldpeak', 'slope', 'ca', 'thal']]
y_p = ds['target']
x_total = x_p.to_numpy()
y_total = y_p.to_numpy()
x_train = x_total[:250]
x_test = x_total[250:]
y_train = y_total[:250]
y_test = y_total[250:]<jupyter_output><empty_output><jupyter_text>Modelling<jupyter_code>model = tensorflow.keras.Sequential([
                          tensorflow.keras.layers.Flatten(),
                          tensorflow.keras.layers.Dense(14, activation='relu'),
                          #tensorflow.keras.layers.Dense(5, activation='relu'),
                          tensorflow.keras.layers.Dense(1, activation='sigmoid')
])
print("Made!")
class lossgobrrr(tensorflow.keras.callbacks.Callback):
  def on_epoch_end(self, epoch, logs={}):
    if (logs.get('loss')<0.05):
      self.model.stop_training = True
      print("UwU Loss low")
lossgobrr = lossgobrrr()
checkpoint_filepath='/Sussy Weights'
checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
    filepath=checkpoint_filepath,
    save_weights_only=True,
    monitor='val_accuracy',
    mode='max',
    save_best_only=True)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print("Compiled!")
model.fit(x=x_train, y=y_train, epochs = 3000, callbacks=[lossgobrr, checkpoint_callback], validation_split=0.1)
model.load_weights(checkpoint_filepath)
print("Trained!...")<jupyter_output>[1;30;43mStreaming output truncated to the last 5000 lines.[0m
8/8 [==============================] - 0s 5ms/step - loss: 0.3643 - accuracy: 0.8267 - val_loss: 0.4239 - val_accuracy: 0.8400
Epoch 502/3000
8/8 [==============================] - 0s 8ms/step - loss: 0.3820 - accuracy: 0.8267 - val_loss: 0.3622 - val_accuracy: 0.9200
Epoch 503/3000
8/8 [==============================] - 0s 8ms/step - loss: 0.3827 - accuracy: 0.8178 - val_loss: 0.3731 - val_accuracy: 0.9200
Epoch 504/3000
8/8 [==============================] - 0s 5ms/step - loss: 0.3434 - accuracy: 0.8578 - val_loss: 0.4166 - val_accuracy: 0.8400
Epoch 505/3000
8/8 [==============================] - 0s 4ms/step - loss: 0.3429 - accuracy: 0.8667 - val_loss: 0.3828 - val_accuracy: 0.9200
Epoch 506/3000
8/8 [==============================] - 0s 5ms/step - loss: 0.3435 - accuracy: 0.8533 - val_loss: 0.4735 - val_accuracy: 0.7600
Epoch 507/3000
8/8 [==============================] - 0s 6ms/step - loss: 0.4332 - accuracy: 0.791[...]<jupyter_text>ZE TEST!<jupyter_code>model.evaluate(x_test, y_test)
random_data = [[57, 1, 0, 150, 276, 0, 0, 112, 1, 0.6, 1, 1, 1]]
print(round(model.predict(random_data)[0][0]))<jupyter_output>0
{'fraction_non_alphanumeric': 0.2100609756097561, 'fraction_numerical': 0.08231707317073171, 'mean_word_length': 4.656896551724138, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '445693', 'license': 'MIT', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1204, 'n_words': 233, 'path': 'Heart_Diesease_Risk_Predictor with saver1.ipynb', 'repo_name': 'stonkmem/Heart-Failure-Predictor', 'size': '3280'}