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

相关推荐
一介书生-0075 分钟前
2025-10-27 Java AI学习路线
java·人工智能·学习
rengang669 分钟前
AI辅助需求分析:AI大模型将自然语言需求转化为技术规格
人工智能·需求分析·ai编程·1024程序员节·ai智能体编程
子不语18010 分钟前
深度学习——IDE之Jupyter
人工智能·深度学习·jupyter
AI小云1 小时前
【Python高级编程】类和实例化
开发语言·人工智能·python
格林威1 小时前
紫外工业相机入门介绍和工业检测核心场景
人工智能·数码相机·计算机视觉·目标跟踪·视觉检测
高洁011 小时前
【无标题】大模型-模型压缩:量化、剪枝、蒸馏、二值化 (2
人工智能·python·深度学习·神经网络·知识图谱
谈思汽车1 小时前
AutoSec Europe 2026 第二届欧洲汽车网络安全与数据安全峰会启动报名!
人工智能
机器之心1 小时前
LSTM之父Jürgen再突破,「赫胥黎-哥德尔机」让AI学会自己进化
人工智能·openai
WWZZ20251 小时前
快速上手大模型:深度学习2(实践:深度学习基础、线性回归)
人工智能·深度学习·算法·计算机视觉·机器人·大模型·slam
初级炼丹师(爱说实话版)2 小时前
算法面经常考题整理(1)机器学习
人工智能·算法·机器学习