0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vtuberレコメンドシステム

Posted at

はじめに


HDCで発表したVtuberレコメンドシステムの中身の計算方法について書こうとおもいます。
今回のレコメンドシステムはコンテンツベースのk近傍法と呼ばれる手法を用いて計算しているんですけど、すべてコードを書いて計算しています。(絶対にライブラリとか使った方が楽だと思う)

計算方法について


1.データが入力されているcsvファイルを読み込み、評価値に欠損があるかどうかを調べてあるものとないものでファイルを分ける。
2.アイテム同士のユークリッド距離を計算する。
3.ユークリッド距離がしきい値以下のものを抽出して評価値を計算
4.評価値の高いものをおすすめに表示

使用したファイル


自作したVtuber_recomend.csvを使用しておすすめのVtuberを計算し、性別やキャラクター性などを段階分けしています。
Vtuber_recomend.csv

段階分けの際に参考にしたもの
https://x.com/gamemarkun/status/1296823453039771650
Ef89pzOU0AA6fHd.jpg

コード全体


import pandas as pd
import math
import numpy as np

#データの読み込み
vtuber = pd.read_csv("Vtuber_recomend.csv", encoding="shift-jis")

# 欠損値が含まれている行を抽出
user = vtuber[vtuber.isna().any(axis=1)]
# インデックスをリセット
user.reset_index(drop=True, inplace=True)

#欠損地が含まれている行を削除
vtuber = vtuber.dropna()
# インデックスをリセット
vtuber.reset_index(drop=True, inplace=True)

#変数の準備
total = 0
total_number = 0
my_list = [0]
my_list_index = [0]
threshold = 3 #しきい値
# ユーザーごとの評価値計算
user_evaluation = []

#ユークリッド距離の計算
for i in range(len(user)):
  evaluation_value = 0  # デフォルト値を設定
  p = np.array([user.loc[i,"性別"],user.loc[i,"ファンタジー"],user.loc[i,"忠実"]])
  for j in range(len(vtuber)):
    q = np.array([vtuber.loc[j,"性別"],vtuber.loc[j,"ファンタジー"],vtuber.loc[j,"忠実"]])
    answer = np.linalg.norm(p - q)

#ユークリッド距離がしきい値以下のものを抽出して評価値を計算
    if(answer <= threshold):
      total += vtuber.loc[j,"評価値"]
      total_number += 1
      evaluation_value = total / total_number

#評価値の最大値をそのindexを配列に入れる
  if(max(my_list) < evaluation_value):
    my_list.pop()
    my_list_index.pop()
    my_list_index.append(i)
    my_list.append(evaluation_value)
  elif (max(my_list) == evaluation_value):
      my_list_index.append(i)
      my_list.append(evaluation_value)
  total = 0
  total_number = 0


#おすすめの表示
for i in range(len(my_list_index)):
  recomend = user.loc[my_list_index[i], "名前"]
  print("あなたのおすすめは:" + recomend + "です")

さいごに


このコードを使用してwebアプリをflaskで作成していました。
チェックをつけたものに評価値を1,-1をファイルに書き込むんで最後に計算って感じ。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?