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

相关推荐
chh5631 小时前
从 BERT 到大模型:让模型从“会接龙”到“会回答
人工智能·深度学习·bert
TomEval2 小时前
【测AI】第26篇:线上模型监控与告警体系 — 测试不是终点
人工智能·python·功能测试·ai
ZhengEnCi2 小时前
AI 总模仿代码库里的过时写法怎么办:先清坏样例,再用类型与测试让 AI 无法犯错
人工智能·ai编程
一只爱撸猫的程序猿3 小时前
五周、两个开源仓库、九次拦截之后:AI 时代程序员缺的到底是什么
人工智能·后端·开源
小毛球.3 小时前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
GitCode官方3 小时前
开源鸿蒙跨平台直播|AI 时代,用 cj-tauri 开发鸿蒙 PC 应用
人工智能·华为·harmonyos·atomgit
老金带你玩AI4 小时前
GPT-6.2更强更便宜了,为什么还有人骂?
人工智能
CyrusYiVPP4 小时前
实测 uv 0.13.7:同一套包,pip 装 94 秒,它只用 19 秒
人工智能·python
泯泷4 小时前
OpenClaw 退潮背后,是 AI 圈“技术自嗨”的终结
人工智能·chatgpt·llm
罗西的思考4 小时前
【轻量化复刻大模型 / KIMI K3】Muon 优化器及 训练系统
人工智能·算法·机器学习