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

相关推荐
AAA修煤气灶刘哥2 分钟前
权重已经读进缓存了,7B 模型怎么还要等 43 秒?
人工智能·性能优化·阿里巴巴
oil欧哟4 分钟前
AI Agent 的高效上下文工程:核心原理与实战拆解
人工智能
邂逅and回眸23 分钟前
机器人的软件栈:ROS 2、实时中间件与数据流
人工智能·中间件·机器人
AAA修煤气灶刘哥25 分钟前
AI 写的 SQL 跑通了,为什么和财务报表对不上?
人工智能·后端·算法
程序员cxuan1 小时前
这 6 个 Gemini 命令,真给我用爽了
人工智能·后端·程序员
狂师2 小时前
别只会用 Playwright、Appium了?这 8 款开源 AI 自动化工具实测推荐!
人工智能·开源·测试
东坡肘子2 小时前
我的代码我做主 -- 肘子的 Swift 周报 #164
人工智能·swiftui·swift
yyzc1111111 小时前
当中小微实体店面临经营困境时如何借助顺成汇创旗下荟生意品牌实现数字化智慧营销
大数据·运维·人工智能
Csvn13 小时前
输出脱敏了,trace 里全是明文——用户数据的四个落点都得堵(S04)
人工智能·aigc·agent
Csvn13 小时前
WorkBuddy 使用指南:模板、SOP、技能、自动化的正确顺序
人工智能