本文整理汇总了Python中sklearn.decomposition.PCA.to_csv方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.to_csv方法的具体用法?Python PCA.to_csv怎么用?Python PCA.to_csv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.to_csv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PCA
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import to_csv [as 别名]
#### Standardisation
import math
from sklearn import preprocessing
depriv_police_scaled = preprocessing.StandardScaler().fit_transform(depriv_police)
depriv_police_scaled = pd.DataFrame(depriv_police_scaled, columns = depriv_police.columns)
depriv_police_scaled.shape #(104045, 12)
depriv_police_scaled.describe()
#### PCA
from sklearn.decomposition import PCA
depriv_police_pca = PCA(n_components = 3)
depriv_police_pca.fit(depriv_police_scaled)
depriv_police_pca = depriv_police_pca.transform(depriv_police_scaled)
depriv_police_pca = pd.DataFrame(depriv_police_pca, columns=["PCA_depriv_police_1", "PCA_depriv_police_2", "PCA_depriv_police_3"])
depriv_police_pca.to_csv("C:/Users/Render02/Desktop/MSc Data Science/Principles of Data Science/Coursework/0. Analysis/2.1 depriv_police_pca.csv")
depriv_police_pca.shape #(104045, 3)
#### Visualisation of PCA and victimisation
colors_victim_vio_sex = ["red" if i==1 else "gray" for i in nvf_all.victim_vio_sex]
fig = plt.figure()
plt.suptitle("Deprivation and attitudes to police PCA & Victim of violence or sex attack")
ax = fig.add_subplot(111, projection="3d")
ax.set_xlabel("PCA 1")
ax.set_ylabel("PCA 2")
ax.set_zlabel("PCA 3")
ax.scatter(depriv_police_pca.PCA_depriv_police_1, depriv_police_pca.PCA_depriv_police_2, depriv_police_pca.PCA_depriv_police_3, c=colors_victim_vio_sex, marker=".")
plt.show()
colors_victim_vio_sex = ["red" if i==1 else "gray" for i in nvf_all.victim_vio_sex]
fig = plt.figure()
开发者ID:acrz823,项目名称:CSEW-Interviewer-gender-the-presence-of-others-and-disclosure-of-violent-victimisation,代码行数:32,代码来源:CSEW+Analysis+on+violent+victimisation.py