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

相关推荐
IT空门:门主7 小时前
Spring AI 2.1.0 更新了什么:从 2.0 升上来的完整梳理
人工智能·python·spring
AI创界者7 小时前
Python 进阶实战(七十章):遗留系统重构、渐进式绞杀与技术债治理实战
人工智能·python·aigc
ZhengEnCi8 小时前
电脑操作 Agent 一直点不中:截图没更新时,提示词该怎么改才能停止瞎试
人工智能·python·agent
甲维斯8 小时前
使用 GPT6.2+UE5 做3D游戏的第一天!
人工智能
字节跳动视频云技术团队8 小时前
不用自建后端,前端页面也能接入云端数据了:Pages Data SDK 正式上线
人工智能·敏捷开发
苏三的开发日记9 小时前
5 个 UI Skill 选型对照表:从需求梳理到方案汇报
人工智能
zhangfeng113310 小时前
2025–2026 国内 AI 赛事盘点:城市级黑客松 / AIGC 创作 / 硬件厂商赛事汇总
人工智能·aigc
麦豆GEO11 小时前
本地生活同城服务如何做好GEO优化
人工智能·生活
邂逅and回眸11 小时前
具身智能入门:机器人是怎么学会干活的
人工智能·机器人
阿里云大数据AI技术12 小时前
SENSER识季 × 阿里云OpenSearch:从时尚灵感到自我表达
人工智能