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

相关推荐
IT_陈寒28 分钟前
SpringBoot这个自动配置坑我跳了三次
前端·人工智能·后端
Larcher1 小时前
AI Loop:让AI像人一样自主完成任务的核心机制
javascript·人工智能·设计模式
牧艺1 小时前
从零到协同:构建类飞书在线文档系统的五个技术重难点
前端·人工智能
CodePlayer竟然被占用了2 小时前
Codex 用电脑的三种姿势:选错模式,你就白烧 Token
人工智能
袋鼠云数栈UED团队2 小时前
一套 Spec-First 的 AI 编程工作流
前端·人工智能
Awu12273 小时前
⚡从零开发 Agent CLI(二):CLI 框架搭建与子命令路由
人工智能·aigc
码上天下3 小时前
React Query 缓存 AI 对话历史的几个权衡
人工智能
米小虾3 小时前
2026半年盘点:AI界发生的6件大事,正在彻底改变产业格局
人工智能
道友可好5 小时前
让 AI 自己验收,等于让学生自己批卷
前端·人工智能·后端