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

相关推荐
数智前线4 分钟前
潮起178,解码AI时代传媒变革的浙江样本
人工智能
Data_Journal7 分钟前
【无标题】
大数据·服务器·前端·数据库·人工智能
阿杰学AI11 分钟前
AI核心知识74——大语言模型之ReAct 范式(简洁且通俗易懂版)
人工智能·ai·语言模型·自然语言处理·aigc·agent·react范式
新缸中之脑13 分钟前
TabPFN:表格数据基础模型
人工智能
工程师老罗22 分钟前
Pytorch中的优化器及其用法
人工智能·pytorch·python
2501_9481201525 分钟前
大语言模型与爬虫技术融合的智能数据采集系统
人工智能·爬虫·语言模型
老蒋每日coding30 分钟前
AI Agentic 交互:从图形界面到现实世界环境
人工智能
github.com/starRTC34 分钟前
Claude Code中英文系列教程24:使用钩子hooks扩展 Claude Code 的行为
人工智能·ai编程
名字不好奇37 分钟前
词嵌入与向量化
人工智能
子午1 小时前
【2026计算机毕设~AI项目】鸟类识别系统~Python+深度学习+人工智能+图像识别+算法模型
图像处理·人工智能·python·深度学习