1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

回帰のためのk-最近傍法アルゴリズム

Posted at
from sklearn.neighbors import KNeighborsRegressor

X, y = mglearn.datasets.make_wave(n_samples=40)

# 分割
X_train, X_test, y_train, y_test = train_test_split(
        X, y, random_state=0)

# インスタンス生成、最近傍点は3にセット
reg = KNeighborsRegressor(n_neighbors=3) 

# モデル学習
reg.fit(X_train, y_train)

# モデル評価
reg.score(X_test, y_test)

なお、回帰予測器はR2スコアを返す
※回帰モデルの予測精度をあらわす指標。0-1までの数値が返され、1に近づくほど高精度な予測

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?