Dev4u Life/Generative AI
(ChatGPT) Show me the code fraud detection using tensorflow
데브포유
2023. 2. 4. 22:39
반응형
Here's a simple example of using TensorFlow to build a binary classification model for fraud detection:
import tensorflow as tf
import pandas as pd
# Load the dataset
data = pd.read_csv("fraud_data.csv")
# Split the data into features (X) and labels (y)
X = data.drop("class", axis=1)
y = data["class"]
# Split the data into training and testing sets
train_X = X[:500]
train_y = y[:500]
test_X = X[500:]
test_y = y[500:]
# Define the model architecture
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation="relu", input_shape=(X.shape[1],)),
tf.keras.layers.Dense(1, activation="sigmoid"),
])
# Compile the model
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
# Train the model
model.fit(train_X, train_y, epochs=10)
# Evaluate the model on the test data
test_loss, test_accuracy = model.evaluate(test_X, test_y)
print("Test Loss:", test_loss)
print("Test Accuracy:", test_accuracy)
# Use the trained model to make predictions on new data
predictions = model.predict(test_X)
반응형