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

相关推荐
JMchen1232 分钟前
Cursor高阶玩法:.cursorrules编写与Spec-Driven开发实战,把AI调教成专属结对编程搭档
人工智能·vscode·kotlin·cursor·结对编程·spec-driven·.cursorrules
szxinmai主板定制专家13 分钟前
基于 RK3588+RK1820/28 算力卡的国产工控机,适用于机器视觉,机器人等边缘算力场景
人工智能·fpga开发·zynq·控制器·mpsoc·半导体设备
右耳朵猫AI24 分钟前
PHP周刊2026W36 | Laravel AI SDK 0.11可观测、Symfony 8.1.5、Octane并发、事件溯源
人工智能·php·laravel
知几蜗牛35 分钟前
ChatGPT Images 2.5更新解析:模板、草图与迭代编辑
人工智能
223糖1 小时前
思考 AI 应用架构
人工智能·架构
IT_陈寒1 小时前
React子组件莫名其妙重渲染?你可能漏了这个Hook
前端·人工智能·后端
张继雁1 小时前
张继雁 个人技术简介|磨削加工过滤方向
大数据·数据库·论文阅读·人工智能·机器学习·创业创新·业界资讯
AIwenIPgeolocation1 小时前
埃文科技签约中部(河南)Token产业运营平台 携手中国电信共创AI新格局
大数据·人工智能·科技
烟雨江南7851 小时前
200路并发语音识别系统实践:CPU、GPU与国产昇腾三种部署方案怎么选?
人工智能·websocket·音视频·语音识别·ai客服
Lumistory1 小时前
从OPPO长安研发中心看头部科技企业的照明运维选择
大数据·运维·人工智能·光照贴图