我有一个形状数据集(70万,20),我想将KNN应用于它。
但是在测试上真的需要很长的时间,能不能请专家帮助我知道如何减少KNN的预测时间。
有什么像GPU或something.Please之类的东西可以帮助我知道吗?
下面是我正在使用的代码。
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
import tensorflow as tf
import pandas as pd
import numpy as np
from joblib import load, dump
import numpy as np
from scipy.spatial import distance
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report
from dtaidistance import dtw
window_length = 20
n = 5
X_train = load('X_train.pth').reshape(-1,20)
y_train = load('y_train.pth').reshape(-1)
X_test = load('X_test.pth').reshape(-1,20)
y_test = load('y_test.pth').reshape(-1)
#custom metric
def DTW(a, b):
return dtw.distance(a, b)
clf = KNeighborsClassifier(metric=DTW)
clf.fit(X_train, y_train)
#evaluate
y_pred = clf.predict(X_test)
print(classification_report(y_test, y_pred))发布于 2022-01-02 17:11:20
度量dtw花费了太多的时间,而简单的knn工作得很好。
https://stackoverflow.com/questions/70533500
复制相似问题