加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 湛江站长网 (https://www.0759zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

数据处理的统计学习(scikit-learn教程)

发布时间:2020-12-26 04:04:51 所属栏目:大数据 来源:网络整理
导读:副标题#e# 数据挖掘入门与实战 ?公众号: datadw Scikit-learn 是一个紧密结合Python科学计算库(Numpy、Scipy、matplotlib),集成经典机器学习算法的Python模块。 一、统计学习:scikit-learn中的设置与评估函数对象 (1)数据集 scikit-learn 从二维数组描

独立成分分析:ICA
独立成分分析(ICA)选择合适的成分使得他们的分布载有最大的独立信息量。可以恢复非高斯独立信号:

# Generate sample datatime = np.linspace(0,10,2000)
s1 = np.sin(2 * time) ?# Signal 1 : sinusoidal signals2 = np.sign(np.sin(3 * time)) ?# Signal 2 : square signalS = np.c_[s1,s2]
S += 0.2 * np.random.normal(size=S.shape) ?# Add noiseS /= S.std(axis=0) ?# Standardize data# Mix dataA = np.array([[1,[0.5,2]]) ?# Mixing matrixX = np.dot(S,A.T) ?# Generate observations# Compute ICAica = decomposition.FastICA()
S_ = ica.fit_transform(X) ?# Get the estimated sourcesA_ = ica.mixing_.T
np.allclose(X,?np.dot(S_,A_) + ica.mean_)

五、联合起来

(1)管道(流水线)

我们已经知道了一些估测器(模型)能够转换数据,一些可以预测变量。我们也能够将其结合到一起:

from sklearn import linear_model,decomposition,datasetsfrom sklearn.pipeline import Pipelinefrom sklearn.grid_search import GridSearchCV
logistic = linear_model.LogisticRegression()
pca = decomposition.PCA()
pipe = Pipeline(steps=[('pca',pca),('logistic',logistic)])
digits = datasets.load_digits()
X_digits = digits.data
y_digits = digits.target################################################################################ Plot the PCA spectrumpca.fit(X_digits)
plt.figure(1,figsize=(4,3))
plt.clf()
plt.axes([.2,.2,.7,.7])
plt.plot(pca.explained_variance_,linewidth=2)
plt.axis('tight')
plt.xlabel('n_components')
plt.ylabel('explained_variance_')################################################################################ Predictionn_components = [20,40,64]
Cs = np.logspace(-4,4,3)
#Parameters of pipelines can be set using ‘__’ separated parameter names:estimator = GridSearchCV(pipe,? ? ? ? ? ? ? ? ? ? ? ? dict(pca__n_components=n_components,? ? ? ? ? ? ? ? ? ? ? ? ? ? ?logistic__C=Cs)) estimator.fit(X_digits,y_digits) plt.axvline(estimator.best_estimator_.named_steps['pca'].n_components,? ? ? ? ? ?linestyle=':',label='n_components chosen') plt.legend(prop=dict(size=12))

(2)使用特征联进行人脸识别

? ?该实例使用的数据集是从“Labeled Faces in the Wild”节选预处理得到的。更为熟知的名字是LFW。

http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz(233 MB)


(编辑:PHP编程网 - 湛江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!