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

相关推荐
阿聪谈架构13 小时前
第13章:AI异步与生产部署 —— 让 AI 服务稳定高效地面向用户
人工智能·后端
黑暗森林观察者14 小时前
AI Agent 的"记忆进化":Skills 自进化框架如何让 Agent 越用越聪明?
人工智能
兆。14 小时前
LangChain大模型服务集成指南:面向AI应用开发者
人工智能·langchain
z小猫不吃鱼14 小时前
05 Transformer Encoder 详解:BERT 为什么使用 Encoder?
深度学习·bert·transformer
刘一说14 小时前
AI科技热点日报 | 2026年5月29日
人工智能·科技
jkyy201414 小时前
AI健康管家:大模型赋能私域健康服务,重塑新零售智慧运营体系
人工智能·零售
薛定猫AI14 小时前
Codex 与 Claude Code 安装配置完全指南
大数据·人工智能·架构
前沿AI14 小时前
AI营销服一体化方案亮相2026中国汽车经销商大会,助力汽车销售全链路提效
大数据·人工智能·汽车
头盔小妹14 小时前
在本地调用大语言模型
人工智能·语言模型·自然语言处理
圣殿骑士-Khtangc14 小时前
智谱AI完成5亿美元融资 + AutoGLM 2.0发布:对标GPT-5 Agent Mode
人工智能