<jupyter_start><jupyter_text>Prepare<jupyter_code>dataset = datasets.load_digits()
X, y = dataset.data, dataset.target

clf = RandomForestClassifier(n_estimators=100, random_state=42)
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)<jupyter_output><empty_output><jupyter_text>Extract feature using scikit-learn interface<jupyter_code># scikit-learn interface
k = 1
transformer = ScikitTransformer(n_neighbors=k)
# working space
number_of_classes = np.unique(y)
X_knn = np.empty([0, len(number_of_classes) * k])

# feature extraction
kf = KFold(n_splits=20, shuffle=False)  # use normal k-Fold to simplify
for train_index, test_index in kf.split(X, y):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

    # fit to training data
    transformer.fit(X_train, y_train)

    # extract feature to test data
    X_test_knn = transformer.transform(X_test)

    # store feature fragment
    X_knn = np.append(X_knn, X_test_knn, axis=0)<jupyter_output><empty_output><jupyter_text>Evaluate: raw data<jupyter_code>score = cross_validate(clf, X, y, cv=skf)
score['test_score'].mean()<jupyter_output><empty_output><jupyter_text>Evaluate: raw -> k-NN feature<jupyter_code>score = cross_validate(clf, X_knn, y, cv=skf)
score['test_score'].mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12012012012012012, 'fraction_numerical': 0.00975975975975976, 'mean_word_length': 6.982035928143713, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '407746', 'license': 'Apache-2.0', 'n_tokens_mistral': 534, 'n_tokens_neox': 514, 'n_words': 90, 'path': 'examples/classification_sklearn.ipynb', 'repo_name': 'momijiame/gokinjo', 'size': '1332'}