Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Import packages and functions import numpy as np import pandas as pd from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split # Import dataset sleep

# Import packages and functions import numpy as np import pandas as pd

from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split

# Import dataset sleep = pd.read_csv('sleep.csv')

# Create input matrix X and output matrix y X = sleep[['bodywt', 'brainwt']] y = sleep[['vore']]

knnModel = KNeighborsClassifier(n_neighbors=6) knnModel = knnModel.fit(X.values, np.ravel(y.values))

neighbors = knnModel.kneighbors(X, return_distance=False)

# Print neighbors print(neighbors)

This dataset contains data on sleep habits for 27 randomly selected mammals. Each mammal is categorized as an omnivore, herbivore, carnivore, or insectivore.

REM sleep cycles of gray seals average 1.5 hours. Gray seals are awake on average 17.8 hours per day.

Use the kneighbors() method to find the instances in the training data that are closest to gray seals. Assign the instances, but not the distances, to neighbors.

The code contains all imports, loads the dataset, initializes the model, and applies the model to a test dataset. The neighbors line is incorrect and I have no idea why, and cannot find documentation on it to figure it out nor does my book help

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago

Question

Which months of this year 5 Mondays ?

Answered: 1 week ago

Question

Define Leap year?

Answered: 1 week ago