Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Multi-Class Classification | k-NN Classifier
Classification with Python

Свайпніть щоб показати меню

book
Multi-Class Classification

Multi-class classification with k-NN is as easy as binary classification. We just pick the class that prevails in the neighborhood.

The KNeighborsClassifier automatically performs a multi-class classification if y has more than two features, so you do not need to change anything. The only thing that changes is the y variable fed to the .fit() method.

Now, you will perform a multi-class classification with k-NN. Consider the following dataset:

1234
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b71ff7ac-3932-41d2-a4d8-060e24b00129/starwars_multiple.csv') print(df.head())
copy

It is the same as in the previous chapter's example, but now the target can take three values:

  • 0: "Hated it" (rating is less than 3/5);

  • 1: "Meh" (rating between 3/5 and 4/5);

  • 2: "Liked it" (rating is 4/5 or higher).

Завдання

Swipe to start coding

You are given the Star Wars ratings dataset stored as a DataFrame in the df variable.

  • Initialize an appropriate scaler and store it in the scaler variable.
  • Calculate the scaling parameters on the training data, scale it, and store the result in the X_train variable.
  • Scale the test data and store the result in the X_test variable.
  • Create an instance of k-NN with 13 neighbors, train it on the training set, and store it in the knn variable.
  • Make predictions on the test set and store them in the y_pred variable.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

book
Multi-Class Classification

Multi-class classification with k-NN is as easy as binary classification. We just pick the class that prevails in the neighborhood.

The KNeighborsClassifier automatically performs a multi-class classification if y has more than two features, so you do not need to change anything. The only thing that changes is the y variable fed to the .fit() method.

Now, you will perform a multi-class classification with k-NN. Consider the following dataset:

1234
import pandas as pd df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/b71ff7ac-3932-41d2-a4d8-060e24b00129/starwars_multiple.csv') print(df.head())
copy

It is the same as in the previous chapter's example, but now the target can take three values:

  • 0: "Hated it" (rating is less than 3/5);

  • 1: "Meh" (rating between 3/5 and 4/5);

  • 2: "Liked it" (rating is 4/5 or higher).

Завдання

Swipe to start coding

You are given the Star Wars ratings dataset stored as a DataFrame in the df variable.

  • Initialize an appropriate scaler and store it in the scaler variable.
  • Calculate the scaling parameters on the training data, scale it, and store the result in the X_train variable.
  • Scale the test data and store the result in the X_test variable.
  • Create an instance of k-NN with 13 neighbors, train it on the training set, and store it in the knn variable.
  • Make predictions on the test set and store them in the y_pred variable.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Ми дуже хвилюємося, що щось пішло не так. Що трапилося?
some-alt