GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/machine_learning/knn_sklearn.py at master · D4VA/Python Expand file tree/ Copy pathknn_sklearn.pyMore file actions 31 lines (22 loc) · 708 Bytes / Copy pathknn_sklearn.pyFile metadata and controls31 lines (22 loc) · 708 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier # Load iris file iris = load_iris() iris.keys() print(f"Target names: \n {iris.target_names} ") print(f"\n Features: \n {iris.feature_names}") # Train set e Test set X_train, X_test, y_train, y_test = train_test_split( iris["data"], iris["target"], random_state=4 ) # KNN knn = KNeighborsClassifier(n_neighbors=1) knn.fit(X_train, y_train) # new array to test X_new = [[1, 2, 1, 4], [2, 3, 4, 5]] prediction = knn.predict(X_new) print( "\nNew array: \n {}" "\n\nTarget Names Prediction: \n {}".format(X_new, iris["target_names"][prediction]) ) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |