<jupyter_start><jupyter_text>流水线在预处理中的应用  标准预处理<jupyter_code>from sklearn.preprocessing import MinMaxScaler
X_transformed = MinMaxScaler().fit_transform(X.values)
X_transformed
X_transformed = MinMaxScaler().fit_transform(X_broken)
estimator = KNeighborsClassifier()
transformed_scores = cross_val_score(estimator, X_transformed, y, scoring='accuracy', cv=3)
print("The 'transformed' average accuracy for is {0:.1f}%".format(np.mean(transformed_scores) * 100))<jupyter_output>The 'transformed' average accuracy for is 82.3%<jupyter_text>2.3流水线<jupyter_code>from sklearn.pipeline import Pipeline
scaling_pipeline = Pipeline([('scale', MinMaxScaler()),
                            ('predict', KNeighborsClassifier())])
scores = cross_val_score(scaling_pipeline, X_broken, y,
                        scoring='accuracy', cv=3)
print("The 'pipeline' average accuracy for is {0:.1f}%".format(np.mean(scores) * 100))<jupyter_output>The 'pipeline' average accuracy for is 82.3%
{'fraction_non_alphanumeric': 0.12280701754385964, 'fraction_numerical': 0.02063983488132095, 'mean_word_length': 6.185185185185185, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '222619', 'license': 'Apache-2.0', 'n_tokens_mistral': 357, 'n_tokens_neox': 336, 'n_words': 60, 'path': 'Chapter 2/Ionosphere Nearest Neighbour.ipynb', 'repo_name': 'flyjump/LearningDataMiningWithPython', 'size': '969'}