Skip to content

Instantly share code, notes, and snippets.

@celsowm
Created November 12, 2023 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celsowm/8871710b0509f76e3e906af9c1235b83 to your computer and use it in GitHub Desktop.
Save celsowm/8871710b0509f76e3e906af9c1235b83 to your computer and use it in GitHub Desktop.
neural_network_tensorflow.py
import tensorflow as tf
import pandas as pd
# Ler o arquivo CSV
df = pd.read_csv('diabetes.csv')
# Extrair os dados para feature_set e labels
feature_set = df.drop('diabetico', axis=1).values
labels = df['diabetico'].values
model = tf.keras.Sequential([
tf.keras.layers.Dense(4, activation='sigmoid', input_shape=(3,)),
tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(feature_set, labels, epochs=20000, batch_size=len(feature_set), verbose=0)
# Predição
single_point = tf.constant([[1, 0, 0]]) # ou [[1, 0, 0]]
result = model.predict(single_point)
limiar = 0.5
resultado = 1 if result[0][0] > limiar else 0
print(resultado)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment