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

相关推荐
小王2041 小时前
Day 32:DeepLab系列与语义分割进阶
深度学习·神经网络·计算机视觉
大模型任我行1 小时前
蚂蚁:金融文档解析新范式
人工智能·语言模型·自然语言处理·金融·论文笔记
IT毕设实战小研1 小时前
基于大数据的AI应用对就业与收入增长的区域差异分析及可视化
大数据·人工智能·python·随机森林·机器学习·课程设计
Magic-ZYJ1 小时前
HarmonyOS 文件选择与读写:DocumentViewPicker、URI、沙箱目录一次搞清
深度学习·华为·harmonyos
音视频牛哥1 小时前
世界模型如何重塑具身智能:从VLA到预测式机器人控制
人工智能·具身智能·世界模型·world model·vla模型·多模态感知·机器人决策
浅安的邂逅1 小时前
260902-Qwen3.8-Max-0902 登顶 Code Arena WebDev:1691 分超 Opus 5
人工智能·ai模型·行业动态·产品发布/更新·模型发布/更新
力学与人工智能1 小时前
智能流体力学专题研讨会特邀报告3|边鑫:混合深度学习与迭代方法的粘性不可压流动加速求解
人工智能·深度学习·流体力学·ppt分享
顿哥GPT1 小时前
ChatGPT Plus / Pro + Codex 实战指南(2026年9月2日)
人工智能·chatgpt
mit6.8242 小时前
AI时代的定位与趋势
人工智能
深念Y2 小时前
Cloudflare Workers AI 服务部署记录
人工智能·语音识别