Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fitting the knn with train-test split
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
- # Optimisation via gridSearch
- knn=KNeighborsClassifier()
- params={'n_neighbors': range(1,40), 'weights':['uniform', 'distance'], 'metric':['minkowski','euclidean'],'algorithm': ['auto','ball_tree','kd_tree', 'brute']}
- k_grd=GridSearchCV(estimator=knn,param_grid=params,cv=5)
- k_grd.fit(X_train,y_train)
- # testing
- yk_grd=k_grd.predict(X_test)
- # calculating the logloss
- print (log_loss(y_test, yk_grd))
- y_true and y_pred contain different number of classes 93, 2. Please provide the true labels explicitly through the labels argument. Classes found in y_true.
- X_train.shape, X_test.shape, y_train.shape, y_test.shape, yk_grd.shape
- # results
- ((742, 192), (248, 192), (742,), (248,), (248,))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement