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

相关推荐
不加辣椒1 小时前
第 4 章 什么是 Harness Engineering
人工智能
桃西西呀1 小时前
上下文窗口都卷到 100 万了,大模型为什么还在为"位置"发愁?
人工智能·llm·ai编程
阿拉斯攀登1 小时前
SpringBoot整合MQTT:后端订阅设备数据、解析传感器报文
人工智能
然我1 小时前
模型不是 Agent:从零实现一个最小 Agent Loop
前端·人工智能·agent
黄油面包1 小时前
Codex 额度三天见底后,我重新做了一周预算
前端·人工智能
AI效率君1 小时前
Deer‑Flow 2.0 + Go‑MCP‑Server(add加法工具)保姆级完整教程
人工智能·agent
阿拉斯攀登1 小时前
SpringCloud微服务MQTT架构:设备消息统一接入、业务分发设计
人工智能
Csvn2 小时前
第 12 章 并行化 Parallelization
人工智能·aigc·agent
大刚测试开发实战2 小时前
我在WorkBuddy上打通了TestHub,全程用AI来跑测试!
人工智能