Deep Learning(3)

Linear Units in Keras

The easiest way to create a model in Keras is through 'keras.Sequential', which creates a stack of layers from a neural network. Of course, we can also use a dense layer to create the model.

We can define a linear model that takes three input features ('sugars', 'fiber', and 'protein') and then generate a simgle output ('calories') like this:

python 复制代码
from tensorflow import keras
from tensorflow.keras import layers

# Create a network with 1 linear unit
model = keras.Sequential([
    layers.Dense(units=1, input_shape=[3])
])

With the first parameter, 'units' , we define how many outputs we want. In this case, we're just predicting 'calories', so we'll use 'units = 1'.

With the second parameter, 'input_shape', we tell Keras the dimension of the inputs. Setting 'input_shape=[3]' ensures that the model will accept three features as input ('sugars', 'fiber', and 'protein').

This model is now ready to be fit to training data

相关推荐
陈广亮3 分钟前
MCP 2026路线图解读.md
人工智能
找藉口是失败者的习惯4 分钟前
【Android】Android 车机 + AI Agent 有没有搞头?
android·人工智能
东离与糖宝5 分钟前
Langflow-ai OpenRAG实战:Java+Spring Boot搭建企业级私有知识库(从0到1)
java·人工智能
Rsun045516 分钟前
Spring AI 面试题
java·人工智能·spring
星浩AI6 分钟前
OpenClaw 总是忘记你说过的话?来试试这个插件
人工智能·后端·agent
tinygone9 分钟前
OpenClaw+FunASR识别飞书发来的音频文件
人工智能·飞书
风停又起9 分钟前
智能体Agent从 0 到 OpenClaw:AI Agent 的完整演进之路
人工智能
CoovallyAIHub21 分钟前
PaveSync:跨国5.2万张图像路面病害基准,7款模型横评(YOLOv8-v12+Faster R-CNN+DETR)
深度学习·算法·计算机视觉
小张贼嚣张21 分钟前
2026年热门开源AI模型合集:部署、安装与实战指南
人工智能·开源