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

相关推荐
2301_809049422 分钟前
WSL Ubuntu24修改g++和cuda toolkit version
人工智能
sunneo5 分钟前
专栏A-AI原生产品设计-01-AI辅助 vs AI原生——产品形态的代际差异
人工智能·语言模型·产品运营·产品经理·ai编程·ai-native
ting94520005 分钟前
Wan2.1-1.3B 深度技术指南:架构、能力、部署与实战全解析
人工智能·架构
热心网友俣先生5 分钟前
2026华中杯A题超详细解题思路+第一篇论文分享
人工智能·算法·机器学习
一个小浪吴啊6 分钟前
MacOS/Linux/Windows 跨平台一键安装OpenCode指南
linux·windows·macos·opencode
介一安全8 分钟前
JADX与AI结合的实操指南:从工具配置到APK分析
人工智能·测试工具·安全性测试·jadx
小草cys8 分钟前
最简单:一根网线直连,mac mini Windows 控制 Mac mini mac
windows·macos·局域网直连
2501_9400417411 分钟前
投喂:AI生成各类游戏提示词
人工智能·游戏·prompt
做cv的小昊14 分钟前
【TJU】研究生应用统计学课程笔记(4)——第二章 参数估计(2.1 矩估计和极大似然估计、2.2估计量的优良性原则)
人工智能·笔记·考研·数学建模·数据分析·excel·概率论
ApachePulsar18 分钟前
演讲回顾|Apache Pulsar: 现代数据架构的消息底座
人工智能·架构