机器学习模型训练
-
ai训练模型有代码吗_模型训练
是的,AI训练模型通常需要使用深度学习框架,如TensorFlow或PyTorch。以下是一个简单的示例,使用TensorFlow训练一个简单的神经网络模型:,,``python,import tensorflow as tf,from tensorflow.keras.models import Sequential,from tensorflow.keras.layers import Dense,,# 准备数据,(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data(),x_train, x_test = x_train / 255.0, x_test / 255.0,,# 创建模型,model = Sequential([, Dense(128, activation='relu', input_shape=(784,)),, Dense(64, activation='relu'),, Dense(10, activation='softmax'),]),,# 编译模型,model.compile(optimizer='adam',, loss='sparse_categorical_crossentropy',, metrics=['accuracy']),,# 训练模型,model.fit(x_train, y_train, epochs=5),,# 评估模型,model.evaluate(x_test, y_test),``