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

相关推荐
java1234_小锋17 分钟前
分享一套优质的基于Python的房屋数据分析预测系统(scikit-learn机器学习+Flask)
python·数据分析·scikit-learn
CCPC不拿奖不改名21 分钟前
RAG基础:基于LangChain 的文本分割实战+文本分块
人工智能·python·langchain·知识库·改行学it·rag·向量库
GIS数据转换器26 分钟前
基于AI的低空数联无人机智慧巡查平台
大数据·人工智能·机器学习·无人机·宠物
J_Xiong011734 分钟前
【Agents篇】09:多智能体协作——分工与涌现
人工智能·ai agent
攒了一袋星辰35 分钟前
Transformer词向量与自注意力机制
人工智能·深度学习·transformer
青春不朽51237 分钟前
TensorFlow 入门指南
人工智能·python·tensorflow
bioinfomatic42 分钟前
对比学习基本原理——以DrugClip为例,从CLIP到DrugClip
人工智能·python
爱吃rabbit的mq43 分钟前
第2章 机器学习的核心概念(上)
人工智能·机器学习
ZCXZ12385296a44 分钟前
YOLO13-C3k2-ConverseB改进:CCTV监控场景下车辆目标检测详解
人工智能·目标检测·目标跟踪
木非哲1 小时前
AB实验高级必修课(二):从宏观叙事到微观侦查,透视方差分析与回归的本质
人工智能·数据挖掘·回归·abtest