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

相关推荐
编码小哥18 小时前
OpenCV Haar级联分类器:人脸检测入门
人工智能·计算机视觉·目标跟踪
程序员:钧念19 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
数据与后端架构提升之路19 小时前
TeleTron 源码揭秘:如何用适配器模式“无缝魔改” Megatron-Core?
人工智能·python·适配器模式
Chef_Chen20 小时前
数据科学每日总结--Day44--机器学习
人工智能·机器学习
这张生成的图像能检测吗20 小时前
(论文速读)FR-IQA:面向广义图像质量评价:放松完美参考质量假设
人工智能·计算机视觉·图像增强·图像质量评估指标
KG_LLM图谱增强大模型20 小时前
本体论与知识图谱:揭示语义技术的核心差异
人工智能·知识图谱·本体论
JicasdC123asd21 小时前
黄瓜植株目标检测:YOLOv8结合Fasternet与BiFPN的高效改进方案
人工智能·yolo·目标检测
爱吃泡芙的小白白21 小时前
深入解析:2024年AI大模型核心算法与应用全景
人工智能·算法·大模型算法
哥布林学者1 天前
吴恩达深度学习课程五:自然语言处理 第二周:词嵌入(二)词嵌入模型原理
深度学习·ai
小程故事多_801 天前
攻克RAG系统最后一公里 图文混排PDF解析的挑战与实战方案
人工智能·架构·pdf·aigc