BernoulliRBM#
- class sklearn.neural_network.BernoulliRBM(n_components=256, *, learning_rate=0.1, batch_size=10, n_iter=10, verbose=0, random_state=None)[source]#
伯努利受限玻尔兹曼机 (RBM)。
具有二元可见单元和二元隐藏单元的受限玻尔兹曼机。参数使用随机最大似然 (SML),也称为持久对比度散度 (PCD) [2] 进行估计。
假设 d ~ n_features ~ n_components,此实现的 time complexity 为
O(d ** 2)。在 用户指南 中阅读更多内容。
- 参数:
- n_componentsint, default=256
隐藏单元的数量。
- learning_ratefloat, default=0.1
权重更新的学习率。强烈建议调整此超参数。合理的值在 10**[0., -3.] 范围内。
- batch_sizeint, default=10
每个小批量中的样本数量。
- n_iterint, default=10
在训练期间对训练数据集执行的迭代/扫描次数。
- verboseint, default=0
详细程度级别。默认值零表示静默模式。值的范围是 [0, inf]。
- random_stateint, RandomState instance or None, default=None
确定用于
从可见层和隐藏层进行吉布斯采样。
初始化组件,在拟合期间从层采样。
在评分样本时破坏数据。
传入一个整数,以便在多次函数调用中获得可重现的结果。请参阅 词汇表。
- 属性:
- intercept_hidden_array-like of shape (n_components,)
隐藏单元的偏差。
- intercept_visible_array-like of shape (n_features,)
可见单元的偏差。
- components_array-like of shape (n_components, n_features)
权重矩阵,其中
n_features是可见单元的数量,n_components是隐藏单元的数量。- h_samples_array-like of shape (batch_size, n_components)
从模型分布中采样的隐藏激活,其中
batch_size是每个小批量中的样本数量,n_components是隐藏单元的数量。- n_features_in_int
在 拟合 期间看到的特征数。
0.24 版本新增。
- feature_names_in_shape 为 (
n_features_in_,) 的 ndarray 在 fit 期间看到的特征名称。仅当
X具有全部为字符串的特征名称时才定义。1.0 版本新增。
另请参阅
sklearn.neural_network.MLPRegressor多层感知器回归器。
sklearn.neural_network.MLPClassifier多层感知器分类器。
sklearn.decomposition.PCA一个无监督的线性降维模型。
References
- [1] Hinton, G. E., Osindero, S. and Teh, Y. A fast learning algorithm for
deep belief nets. Neural Computation 18, pp 1527-1554. https://www.cs.toronto.edu/~hinton/absps/fastnc.pdf
- [2] Tieleman, T. Training Restricted Boltzmann Machines using
Approximations to the Likelihood Gradient. International Conference on Machine Learning (ICML) 2008
示例
>>> import numpy as np >>> from sklearn.neural_network import BernoulliRBM >>> X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]) >>> model = BernoulliRBM(n_components=2) >>> model.fit(X) BernoulliRBM(n_components=2)
有关更详细的示例用法,请参阅 用于数字分类的受限玻尔兹曼机特征。
- fit(X, y=None)[source]#
将模型拟合到数据 X。
- 参数:
- Xshape 为 (n_samples, n_features) 的 {array-like, sparse matrix}
训练数据。
- y形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组对象,默认=None
目标值(对于无监督转换,为 None)。
- 返回:
- selfBernoulliRBM
拟合后的模型。
- fit_transform(X, y=None, **fit_params)[source]#
拟合数据,然后对其进行转换。
使用可选参数
fit_params将转换器拟合到X和y,并返回X的转换版本。- 参数:
- Xshape 为 (n_samples, n_features) 的 array-like
输入样本。
- y形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组对象,默认=None
目标值(对于无监督转换,为 None)。
- **fit_paramsdict
额外的拟合参数。仅当估计器在其
fit方法中接受额外的参数时才传递。
- 返回:
- X_newndarray array of shape (n_samples, n_features_new)
转换后的数组。
- get_feature_names_out(input_features=None)[source]#
获取转换的输出特征名称。
The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are:
["class_name0", "class_name1", "class_name2"].- 参数:
- input_featuresarray-like of str or None, default=None
Only used to validate feature names with the names seen in
fit.
- 返回:
- feature_names_outstr 对象的 ndarray
转换后的特征名称。
- get_metadata_routing()[source]#
获取此对象的元数据路由。
请查阅 用户指南,了解路由机制如何工作。
- 返回:
- routingMetadataRequest
封装路由信息的
MetadataRequest。
- get_params(deep=True)[source]#
获取此估计器的参数。
- 参数:
- deepbool, default=True
如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- gibbs(v)[source]#
执行一次吉布斯采样步骤。
- 参数:
- vndarray of shape (n_samples, n_features)
用于开始可见层的值。
- 返回:
- v_newndarray of shape (n_samples, n_features)
一次吉布斯步骤后可见层的值。
- partial_fit(X, y=None)[source]#
将模型拟合到数据 X 的部分段。
- 参数:
- Xndarray of shape (n_samples, n_features)
训练数据。
- y形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组对象,默认=None
目标值(对于无监督转换,为 None)。
- 返回:
- selfBernoulliRBM
拟合后的模型。
- score_samples(X)[source]#
计算 X 的伪似然。
- 参数:
- Xshape 为 (n_samples, n_features) 的 {array-like, sparse matrix}
可见层的值。必须全部为布尔值 (未检查)。
- 返回:
- pseudo_likelihoodndarray of shape (n_samples,)
伪似然值 (似然的代理)。
注意事项
此方法不是确定性的:它计算 X 上的一个称为自由能的数量,然后计算 X 的随机损坏版本的自由能,并返回两者的差值的 logistic 函数的对数。
- set_output(*, transform=None)[source]#
设置输出容器。
有关如何使用 API 的示例,请参阅引入 set_output API。
- 参数:
- transform{“default”, “pandas”, “polars”}, default=None
配置
transform和fit_transform的输出。"default": 转换器的默认输出格式"pandas": DataFrame 输出"polars": Polars 输出None: 转换配置保持不变
1.4 版本新增: 添加了
"polars"选项。
- 返回:
- selfestimator instance
估计器实例。