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

相关推荐
量化分析码农9 分钟前
股票API 日线、周线、月线与分钟级返回结构差异:一份统一解析代码
人工智能
这个DBA有点耶10 分钟前
MCP隔离层+行级语义审计+输出校验:AI访问数据库的安全边界拆解
数据库·人工智能·ai编程
IT_陈寒19 分钟前
Vue的watch把我坑惨了,原来要这样用才靠谱
前端·人工智能·后端
`流年づ25 分钟前
策略梯度(Policy Gradient)
人工智能
疯华整猫39 分钟前
删掉 LeakCanary 那天,我用 Trae 自己撸了一套:最难的不是分析堆,是决定什么时候 dump
android·人工智能·性能优化
慢慢来不要急1 小时前
Anthropic 弃用 Git 自建源码控制系统 · 11-11
人工智能·开发工具
用户别睡觉1 小时前
有时候放弃也是一种收获
人工智能·github
shengjk11 小时前
从一条 Bash 命令看懂 LLM Agent:为什么大模型会执行命令?
人工智能
Yuzhiyuxia2 小时前
【AI Agent面试系列】AI Agent可观测、评测、安全相关的知识点
人工智能·安全·面试
dozenyaoyida2 小时前
AI与大模型新闻日报 | 2026-11-11
人工智能·chatgpt·大模型·新闻