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

相关推荐
广州山泉婚姻7 小时前
Python爬虫 + AI 极简实战
人工智能·python
ghgxm5207 小时前
Opencode入门
人工智能·opencv
竹之却7 小时前
【Agent-阿程】AI先锋杯·14天征文挑战第14期-第9天-大模型服务端高效部署与vLLM实战
人工智能·vllm
财经资讯数据_灵砚智能7 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年4月15日
大数据·人工智能·信息可视化·自然语言处理·ai编程
归零鸟7 小时前
中东局势的全球影响研究——油价和供应链中断给经济发展和个人生活带来的变化
大数据·人工智能·生活
码农的日常搅屎棍7 小时前
视觉标定--眼在手上整相机标定步骤适配随机工作平面
人工智能·数码相机·计算机视觉
大江东去浪淘尽千古风流人物7 小时前
【DROID-W】WildGS-SLAM
数据库·人工智能·python·oracle·augmented reality
承渊政道7 小时前
【递归、搜索与回溯算法】(二叉树深搜模型拆解与经典题型全面突破)
数据结构·c++·学习·算法·leetcode·macos·bfs
xiaoyaohou117 小时前
034、特定场景优化(一):小目标检测的改进策略合集
人工智能·目标检测·计算机视觉
何玺7 小时前
从HappyHorse到Seedance:AI视频的“四强争霸”终局推演
人工智能·音视频