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

相关推荐
爱淋雨的男人8 分钟前
自动驾驶感知相关算法
人工智能·算法·自动驾驶
互联网科技看点9 分钟前
AI算力爆发叠加数据资产风口,铂拉锐科技布局去中心化数字生态
人工智能·科技·去中心化
如若12312 分钟前
flash-attn 安装失败?从报错到成功的完整排雷指南(CUDA 12.8 + PyTorch 2.7)
人工智能·pytorch·python
七牛云行业应用17 分钟前
GPT-5.4能力前瞻:解析原生电脑操控(Computer Use)原理与Agent架构构建
人工智能·chatgpt·大语言模型·ai agent·mcp协议
带娃的IT创业者20 分钟前
Prompt Engineering 进阶:让 AI 写出人类味道(完整指南)
人工智能·大模型·llm·prompt·写作技巧·ai 教学
简佐义的博客28 分钟前
转录组数据分析实战,仅需99元(视频版)
大数据·人工智能·数据挖掘·数据分析·音视频
bst@微胖子28 分钟前
OpenCV 案例一【人脸检测】
人工智能·opencv·计算机视觉
小鸡吃米…32 分钟前
自然语言处理的应用
人工智能·自然语言处理·nlp
jiang_changsheng38 分钟前
AutoClaw 安全与风险使用指南
人工智能
咚咚王者1 小时前
人工智能之语言领域 自然语言处理 第六章 情感分析
人工智能·自然语言处理·easyui