Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

knn.score sklearn

# Author: Pablo Marcos Manchón
# License: MIT
# https://fda.readthedocs.io/en/latest/auto_examples/plot_k_neighbors_classification.html
  
import skfda
from skfda.ml.classification import KNeighborsClassifier

from sklearn.model_selection import (train_test_split, GridSearchCV,
                                     StratifiedShuffleSplit)

import matplotlib.pyplot as plt
import numpy as np

X, y = skfda.datasets.fetch_growth(return_X_y=True, as_frame=True)
X = X.iloc[:, 0].values
y = y.values

# Plot samples grouped by sex
X.plot(group=y.codes, group_names=y.categories)

y = y.codes

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25,
                                                    stratify=y, random_state=0)
                                                    
knn = KNeighborsClassifier()
knn.fit(X_train, y_train)

pred = knn.predict(X_test)
print(pred)

# The score() method allows us to calculate 
# the mean accuracy for the test data.
score = knn.score(X_test, y_test)
print(score)
Comment

PREVIOUS NEXT
Code Example
Python :: perform cross tabulation sklearn 
Python :: merging results from model.predict() prediction with original pandas dataframe 
Python :: sns.kdeplot make line more detailed 
Python :: ring Create Lists 
Python :: ring convert string lines to list items and convert the list to a string 
Python :: ring write the key and the IV directly using strings 
Python :: update specific field in index in elastic using python 
Python :: ring The For Loops uses the local scope 
Python :: ring execute the program line by line 
Python :: create schema for table for django 
Python :: python adx indicator 
Python :: dateentry python centered 
Python :: matplotlib doesnt show suptitle 
Python :: Convert matlab to Python Reddit 
Python :: global variable not accessible withing thread 
Python :: Python Root finding code 
Python :: how to hash out a big paragraph in vs code python 
Python :: voilion plot 
Python :: django reverse accessor clashes for abstract class 
Python :: ptyhton json respones 
Python :: prime numbers from 1 to 100 in python 
Python :: disable json dumps encode 
Python :: can I activate a function inside the definition of the same function 
Python :: pyplot common labels 
Python :: python loop chrome 
Python :: remove uppercase letters python 
Python :: python class optional arguments 
Python :: python ListObjectsV2 over 1000 
Python :: pydantic model and ORM model 
Python :: how to get each word in a string 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =