在sklearn-python工具箱中,有两个函数
和
关于
..。下面是两个函数的描述


但是它们之间的区别是什么呢?
发布于 2014-05-24 05:59:04
The The The
方法是为了在您已经计算了
,即如果您已经调用了它的
方法。
In [12]: pc2 = RandomizedPCA(n_components=3)
In [13]: pc2.transform(X) # can't transform because it does not know how to do it.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
----> 1 pc2.transform(X)
/usr/local/lib/python3.4/dist-packages/sklearn/decomposition/pca.py in transform(self, X, y)
    714         # XXX remove scipy.sparse support here in 0.16
    715         X = atleast2d_or_csr(X)
--> 716         if self.mean_ is not None:
    717             X = X - self.mean_
    718 
AttributeError: 'RandomizedPCA' object has no attribute 'mean_'
In [14]: pc2.ftransform(X) 
pc2.fit            pc2.fit_transform  
In [14]: pc2.fit_transform(X)
Out[14]: 
array([[-1.38340578, -0.2935787 ],
       [-2.22189802,  0.25133484],
       [-3.6053038 , -0.04224385],
       [ 1.38340578,  0.2935787 ],
       [ 2.22189802, -0.25133484],
       [ 3.6053038 ,  0.04224385]])所以你想
然后
作为:
In [20]: pca = RandomizedPCA(n_components=3)
In [21]: pca.fit(X)
Out[21]: 
RandomizedPCA(copy=True, iterated_power=3, n_components=3, random_state=None,
       whiten=False)
In [22]: pca.transform(z)
Out[22]: 
array([[ 2.76681156,  0.58715739],
       [ 1.92831932,  1.13207093],
       [ 0.54491354,  0.83849224],
       [ 5.53362311,  1.17431479],
       [ 6.37211535,  0.62940125],
       [ 7.75552113,  0.92297994]])
In [23]:尤其是PCA
应用通过对矩阵进行PCA分解而获得的基数的变化
添加到矩阵中
..。
发布于 2017-04-08 23:53:34
在
scikit学习估计器api
:用于从训练数据生成学习模型参数
:参数生成自
方法,应用于模型,生成转换后的数据集。
:组合
和
同一数据集上的api

结帐
第四章
从这里
书
答案来自
stackexchange
为了更清晰
发布于 2018-06-18 15:42:13
这些方法用于对给定数据进行居中/特征缩放。它基本上有助于对特定范围内的数据进行标准化
为此,我们使用Z-score方法。

我们在训练数据集上做到这一点。
1.
拟合():
方法计算参数μ和σ并将它们保存为内部对象。
2.
Transform():
方法使用这些计算出的参数将转换应用于特定的数据集。
3.
适合
_
transform():
联接fit()和transform()方法以转换数据集。
用于特征缩放/标准化的代码片段(训练后
_
测试
_
拆分)。
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit_transform(X_train)
sc.transform(X_test)我们在我们的测试集上应用相同的(训练集相同的两个参数μ和σ(值))参数转换。
https://stackoverflow.com/questions/23838056
复制相似问题