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

相关推荐
edtoplort5 分钟前
A股最大IPO长鑫科技295亿:从年亏163亿到日赚3亿
大数据·人工智能·科技
道影子11 分钟前
《道德经》031兵者不祥,胜以丧礼处之
人工智能·深度学习·算法
MGS浪疯15 分钟前
我用 WorkBuddy 做了一个能记住前文的 AI 小说编辑器
人工智能·编辑器·腾讯云·腾讯云ai代码助手·workbuddy开发者分享季·codebuddy开发者分享季
IT_陈寒16 分钟前
Python的线程池把我CPU跑满了,原来少传了个参数
前端·人工智能·后端
Microvision维视智造19 分钟前
买视觉系统踩过的坑,都是选型时没问对的问题,真实案例手把手教你选择视觉合作伙伴!
人工智能·计算机视觉·视觉检测·机器视觉
BSD_CGQ20 分钟前
FSR压力传感器的MCU采集方案与校准算法实现
人工智能·计算机视觉·目标跟踪·adc·压力传感器·fsr·深圳源头厂家
老猿AI洞察34 分钟前
阿里Qwen-Image-3.0发布:4.5K token长输入+10px小字渲染,AI生图终于能从“好看“走向“好用“了
人工智能·阿里云
愚公搬代码36 分钟前
测试测试测试测试测试测试
人工智能
淼澄研学43 分钟前
深入解析AI不确定推理:5种工程化落地方案与代码实战
人工智能
RSABLOCKCHAIN44 分钟前
AI Agents in LangGraph-1
人工智能·系统架构