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

相关推荐
诸葛务农2 分钟前
涡喷式发烟机施放粉末状烟剂成烟面积的计算:烟剂材料特性的影响
人工智能
云烟成雨TD16 分钟前
Agent Scope Java 2.x 系列【10】技能(Skill)
java·人工智能·agent
GDAL18 分钟前
书签栏的 AI 转型:用 bge-small-zh-v1.5 重塑书签管理
人工智能·书签栏
青山如墨雨如画23 分钟前
【北邮-无线通信中的人工智能】物理层技术中AI的应用实践:基于KNN的调制识别(1)理论基础
人工智能·python·机器学习·matlab·jupyter
xhtdj39 分钟前
智源大会圆桌大模型没有终局具身智能可能是中国的 AlphaGo 时刻
人工智能·clickhouse·安全·动态规划
HavenlonLabs41 分钟前
区块链解决信任分布,AI 需要解决能力控制
人工智能·安全·区块链
良枫44 分钟前
01 “自进化 Agent”是什么
人工智能
LaughingZhu1 小时前
Product Hunt 每日热榜 | 2026-06-12
人工智能·经验分享·深度学习·神经网络·产品运营
数据门徒1 小时前
神经网络原理 第十一章:植根于统计力学的随机机器和它们的逼近
人工智能·深度学习·神经网络
AI 编程助手GPT1 小时前
用 Python 做一个世界杯赛前分析脚本:以巴西 vs 摩洛哥为例
开发语言·网络·人工智能·python·chatgpt