1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import numpy as np
- from sklearn.neighbors import KNeighborsClassifier
- from sklearn.model_selection import train_test_split, cross_val_score
- import matplotlib.pyplot as plt
- from datasets import Datasets
- def get_feature(cmd, fdist):
- feature = []
- for block in cmd:
- v = [0] * len(fdist)
- for i in range(0, len(fdist)):
- if fdist[i] in block:
- v[i] += 1
- feature.append(v)
- return feature
- def main():
- data, y, fdist = Datasets.load_Schonlau('User3')
- x = get_feature(data, fdist)
-
-
-
-
- x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)
-
- knn = KNeighborsClassifier(n_neighbors=3)
-
-
-
-
- scores = cross_val_score(knn, x, y, cv=10, scoring="accuracy")
- print(scores.mean())
-
-
-
-
-
-
-
-
-
-
-
-
-
- if __name__ == "__main__":
- main()
|