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

相关推荐
泰迪智能科技013 分钟前
职业技术证书推荐:机器学习工程师证书
人工智能·机器学习
冬奇Lab21 分钟前
企业知识库系列(01):为什么 RAG 只是起点
人工智能
冬奇Lab31 分钟前
开源项目第185期:Orca — YC 支持的 AI Agent 开发环境,并行运行多个 Coding Agent、手机远程监控、Design Mode 直接截图喂给 AI
人工智能·开源·资讯
LPCK_2026062240 分钟前
2026 企业智能体:私有化与 SaaS 部署对比,从安全成本看落地选型
人工智能·安全
学着改变2751 小时前
手持式超声波流量计为何首选行澳科技?便携巡检与外夹计量的性能标杆
大数据·网络·人工智能·科技·产品运营·量子计算
破烂pan1 小时前
AI-Agent-Book第一章思考题
人工智能·agent
AI服务老曹2 小时前
AI视频分析API常见问题和排查清单
人工智能·音视频
youngerwang2 小时前
【从“聊天“到“执行“:MATLAB Agentic AI + MCP Server 实战——以 5G NR PDSCH 波形仿真为例】
人工智能·5g·matlab
沸速存储2 小时前
CPU 和 GPU 核心差别在哪?为什么 AI 训练离不开 GPU
服务器·人工智能·科技·嵌入式硬件·电脑
leoZ2312 小时前
AI 辅助开发的五道坎
开发语言·人工智能·视觉检测·bert·php·超分辨率重建·openvino