如何通过 make_pipeline() 标准化训练和测试数据集
How to standardize a training and a test dataset through make_pipeline()
我正在学习如何使用 make_pipeline 运行 K 均值模型来标准化我的数据集列的值。
我正在学习 DataCamp 课程,但我不清楚为什么他们在同一数据集上拟合和预测模型 - 在 Datacamp 案例中 "movements",一个每日股票价值数据集。我认为 K-means 模型的全部目的是在训练数据集上进行训练并预测测试数据集?
与 Datacamp 案例不同,我想在列标准化训练数据集上训练我的模型,并在列标准化测试数据集上对其进行测试。怎么做?我正在复制并粘贴下面的 Datacamp 代码以供参考。
# Import Normalizer
from sklearn.preprocessing import Normalizer
# Create a normalizer: normalizer
normalizer = Normalizer()
# Create a KMeans model with 10 clusters: kmeans
kmeans = KMeans(n_clusters = 5)
# Make a pipeline chaining normalizer and kmeans: pipeline
pipeline = make_pipeline(normalizer, kmeans)
# Fit pipeline to the daily price movements
pipeline.fit(movements)
# Predict the cluster labels: labels
labels = pipeline.predict(movements)
我认为您混淆了 KNN 和 K-Means 模型。 KNN 是一种用于分类和回归监督学习的模型,而 K-Means 是一种聚类模型,属于无监督学习(这里没有目标变量!),通常不进行训练和测试拆分.
如果您打算衡量 K-Means 的性能,请阅读 here
我正在学习如何使用 make_pipeline 运行 K 均值模型来标准化我的数据集列的值。
我正在学习 DataCamp 课程,但我不清楚为什么他们在同一数据集上拟合和预测模型 - 在 Datacamp 案例中 "movements",一个每日股票价值数据集。我认为 K-means 模型的全部目的是在训练数据集上进行训练并预测测试数据集?
与 Datacamp 案例不同,我想在列标准化训练数据集上训练我的模型,并在列标准化测试数据集上对其进行测试。怎么做?我正在复制并粘贴下面的 Datacamp 代码以供参考。
# Import Normalizer
from sklearn.preprocessing import Normalizer
# Create a normalizer: normalizer
normalizer = Normalizer()
# Create a KMeans model with 10 clusters: kmeans
kmeans = KMeans(n_clusters = 5)
# Make a pipeline chaining normalizer and kmeans: pipeline
pipeline = make_pipeline(normalizer, kmeans)
# Fit pipeline to the daily price movements
pipeline.fit(movements)
# Predict the cluster labels: labels
labels = pipeline.predict(movements)
我认为您混淆了 KNN 和 K-Means 模型。 KNN 是一种用于分类和回归监督学习的模型,而 K-Means 是一种聚类模型,属于无监督学习(这里没有目标变量!),通常不进行训练和测试拆分.
如果您打算衡量 K-Means 的性能,请阅读 here