0% found this document useful (0 votes)
5 views1 page

RNA2

The document outlines a machine learning workflow for predicting diabetes using a dataset. It includes data loading, preprocessing, model creation with Keras, training, and evaluation. The model's accuracy is printed after training, and predictions are rounded for interpretation.

Uploaded by

Cristian Isaza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

RNA2

The document outlines a machine learning workflow for predicting diabetes using a dataset. It includes data loading, preprocessing, model creation with Keras, training, and evaluation. The model's accuracy is printed after training, and predictions are rounded for interpretation.

Uploaded by

Cristian Isaza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pandas as pd

from sklearn.model_selection import train_test_split


#Datos
#encabezado
#Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFuncti
on,Age,Outcome
total_data = pd.read_csv("DiabetesP.csv")

X = total_data.drop("8", axis = 1)
y = total_data["8"]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2,


random_state = 42)

X_train.head()

#se entrena el modelo


from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.utils import set_random_seed

set_random_seed(42)

model = Sequential()
model.add(Dense(12, input_shape = (8,), activation = "relu"))
model.add(Dense(8, activation = "relu"))
model.add(Dense(1, activation = "sigmoid"))

model.compile(loss = "mean_squared_error", optimizer = "SGD", metrics =


["accuracy"])
model

# Ajustar el modelo de keras en el conjunto de datos


historial=model.fit(X_train, y_train, epochs = 150, batch_size = 10)

import matplotlib.pyplot as plt


plt.xlabel("# Epoca")
plt.ylabel("Magnitud de pérdida")
plt.plot(historial.history["loss"])

_, accuracy = model.evaluate(X_train, y_train)

print(f"Accuracy: {accuracy}")

y_pred = model.predict(X_test)
y_pred[:15]

#redondeo de la salida
y_pred_round = [round(x[0]) for x in y_pred]
y_pred_round[:15]

You might also like