AI Learning
HTML-код
- Опубликовано: 5 окт 2024
- An introduction to AI focusing on building a Binary AI.
Cancer File: github.com/Voi...
Google CoLab: colab.research...
Pandas: pandas.pydata....
NumPy: numpy.org/
TensorFlow: www.tensorflow...
SKLearn: scikit-learn.o...
Full Code:
# Import Libraries
import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split
# Load the dataset
dataset = pd.read_csv('cancer.csv')
x = dataset.drop(columns=["diagnosis(1=m, 0=b)"])
y = dataset["diagnosis(1=m, 0=b)"]
# Split the dataset into training and test sets
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
# Build and train the model
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Dense(256, input_shape=x_train.shape[1:], activation='sigmoid'))
model.add(tf.keras.layers.Dense(256, activation='sigmoid'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1000)
# Evaluate the model on the test set
loss, accuracy = model.evaluate(x_test, y_test)
print(f"Accuracy on the test set: {accuracy}")
# Prepare and predict the new tumor data
new_tumor_data = np.array([[13.54, 14.36, 87.46, 566.3, 0.09779, 0.08129, 0.06664, 0.04781, 0.1885, 0.05766, 0.2699, 0.7886, 2.058, 23.56, 0.008462, 0.0146, 0.02387, 0.01315, 0.0198, 0.0023, 15.11, 19.26, 99.7, 711.2, 0.144, 0.1773, 0.239, 0.1288, 0.2977, 0.07259]])
prediction = model.predict(new_tumor_data)
print(f"Prediction for the new tumor data: {prediction}")
# Determine the diagnosis based on the prediction
threshold = 0.5
accuracy_rating = accuracy
diagnosis = "malignant" if prediction >= threshold else "benign"
print(f"The predicted diagnosis is: {diagnosis}. Accuracy: {accuracy_rating}")