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

相关推荐
Bruce_Liuxiaowei3 分钟前
2026年7月第1周网络安全形势周报
人工智能·安全·web安全·ai·智能体
A.说学逗唱的Coke10 分钟前
【大模型专题】Claude Haiku vs Sonnet vs Opus:三款模型深度对比与选型指南(2026最新)
大数据·人工智能
梦想的旅途214 分钟前
基于RPA技术的企业微信自动化接口设计思路与应用实践
人工智能·机器人·自动化·企业微信·rpa
2601_9545267514 分钟前
【工控底层架构】进口阀门和国产阀门哪个性价比高?从TCO模型到边缘诊断源码的全栈解析
人工智能·架构·硬件工程
CCPC不拿奖不改名15 分钟前
Redis 工程化部署深度解析
linux·服务器·数据库·redis·深度学习·缓存·rag
sunywz16 分钟前
【AI智能客服系统】02.项目部署与运行
人工智能
JackHCC19 分钟前
自进化智能体协同进化综述
人工智能·机器学习
项目管理者20 分钟前
PMP 专业项目管理软件核心应用场景指南
人工智能·甘特图·敏捷流程
Arranging1578821 分钟前
会议纪要整理场景下主流办公效率工具使用体验分析
人工智能
cd_9492172128 分钟前
AI Infra选型指南:企业算力底座怎么建
人工智能