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

相关推荐
一知半解仙几秒前
2026年彻底免费的辅助编程Agent大模型汇总
开发语言·人工智能·开源
2301_767113981 分钟前
Ollama 本地部署与运维使用指南
人工智能·ollama
2501_9110676617 分钟前
乡村振兴 + 零碳民生稿:叁仟光伏智慧灯杆,点亮杭州共富乡村绿色数字路
人工智能·5g·重构·生活·智慧城市
linzᅟᅠ31 分钟前
README
人工智能·python
小猴子下山12337 分钟前
2026年无锡细胞存储市场格局观察:四家企业的传承脉络与业务分野
大数据·人工智能·精选
Database_Cool_41 分钟前
数据库慢查询优化首选方案:阿里云 RDS 性能洞察+自动诊断
数据库·人工智能·阿里云
2601_9516599941 分钟前
YOLOv11 改进 - 主干网络 ConvNeXtV2全卷积掩码自编码器网络:轻量级纯卷积架构破解特征坍塌难题,提升特征多样性
深度学习·yolo·计算机视觉
北邮刘老师1 小时前
国标配套开源实现再升级!AIP智能体互联开源项目v2.1.0正式发布
人工智能·开源·大模型·智能体·智能体互联网
zhoupenghui1681 小时前
【AI大模型应用开发】【项目实战】13.RAG智慧问答项目-(一)项目介绍&项目架构&项目环境配置
人工智能·docker·ai·milvus·rag·attu·rag智慧问答项目
神奇小汤圆1 小时前
AI Coding 不只靠 Prompt:Agent 工程闭环如何接入 DevOps
人工智能