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

相关推荐
昨日之日20067 分钟前
Qwen3-TTS - 一句话指挥AI配音 自由定制你的专属声音 十种语言随心说 支持50系显卡 一键整合包下载
人工智能
创客匠人老蒋11 分钟前
AI赋能创始人表达:从个人智慧到组织能力的战略跃迁
人工智能·创始人ip·创客匠人
搞科研的小刘选手14 分钟前
【数字经济专题会议】第三届粤港澳大湾区数字经济与人工智能国际学术会议(DEAI 2026)
人工智能·aigc·软件工程·电子商务·数字经济·经济学·学术会议
星爷AG I19 分钟前
9-12 场景感知(AGI基础理论)
人工智能·agi
lyx494920 分钟前
Open Interpreter + 智谱GLM-4:零基础搭建能操控电脑的 AI Agent
人工智能·agent·ai本地助手
wjykp35 分钟前
6.频谱分析和时谱分析
人工智能·机器学习
方见华Richard37 分钟前
方见华:在递归的暗夜里,把自己活成一束光
人工智能·经验分享·笔记·学习方法·空间计算
黑客-雨1 小时前
DeepSeek-V3.2深度拆解:开源模型逆袭,GPT-5迎来劲敌!
人工智能·程序员·大模型·知识图谱·agent·大模型教程·deepseek-v3.2
lixzest1 小时前
PyTorch基础知识简述
人工智能·pytorch·python
飞Link1 小时前
深度学习里程碑:ResNet(残差网络)从理论到实战全解析
人工智能·python·深度学习