on
ai 주식투자
- Get link
- X
- Other Apps
Keras: High-Level Neural Networks API
Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, Theano, or CNTK. It focuses on enabling fast experimentation and is known for its user-friendliness. It's designed to make building and training neural networks as easy as possible.
Key Features & Why it's Useful:
Simple Example:
import keras
from keras.models import Sequential
from keras.layers import Dense
# Define the model
model = Sequential()
model.add(Dense(128, activation='relu', input_shape=(784,))) # Input layer with 784 features
model.add(Dense(10, activation='softmax')) # Output layer with 10 classes
# Compile the model
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
# Load and preprocess data (example using MNIST)
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = x_train.reshape(60000, 784).astype('float32') / 255
x_test = x_test.reshape(10000, 784).astype('float32') / 255
y_train = keras.utils.to_categorical(y_train, num_classes=10)
y_test = keras.utils.to_categorical(y_test, num_classes=10)
# Train the model
model.fit(x_train, y_train, epochs=2)
# Evaluate the model
loss, accuracy = model.evaluate(x_test, y_test)
print('Test accuracy:', accuracy)
Comments
Post a Comment