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

相关推荐
CoderJia程序员甲12 分钟前
GitHub 热榜项目 - 日榜(2026-04-05)
人工智能·ai·大模型·github·ai教程
LaughingZhu21 分钟前
Anthropic 收购 Oven 后,Claude Code 用运行时写了一篇护城河文章
大数据·人工智能·经验分享·搜索引擎·语音识别
Devil枫24 分钟前
AI+地图:一句话,实现智能周边推荐与路线规划
人工智能
茫茫人海一粒沙35 分钟前
Function Calling vs Tool Calling:从机制到架构的统一认知框架
人工智能
qq_5710993535 分钟前
学习周报三十九
人工智能·深度学习·机器学习
陈天伟教授36 分钟前
Hugging Face 快速入门手册(实操案例-心电心音同步分析)
人工智能
H Journey1 小时前
openCV学习之-腐蚀
人工智能·opencv·学习
陈天伟教授1 小时前
小白快速进阶- AI辅助编码
人工智能·神经网络·机器学习·量子计算
AI成长日志1 小时前
【GitHub开源项目专栏】黑客松获奖项目技术深潜:从垂直领域AI到安全基础设施的创新实践
人工智能·开源·github
H Journey1 小时前
openCV图像学-二值化
人工智能·opencv·计算机视觉