カテゴリー: おひメーター

  • おひメーター20260114実績速報

    2026/01/14Youtube音源再生データYoutubeMV再生データUSEN推しリクSpotifyバイラル合計
    再生数いいね数コメント数再生数いいね数コメント数順位daily20bonus順位daily50bonus
    本日の実績169859067791446488200
    本日のおひメーター169851800600779149280882000019477.9
    前日までの実績157910261112212731623588221327
    前日までのおひメーター157910522201220012731627176402132700434583.2
    本日までの実績174895270112813510763634622209
    本日までの
    累積おひメーター
    17489554020128001351076726920222090000454061.1

    データコラム連載

    Youtubeコメントを分析する。

     おひさまでぃすこーどでは今シングル向けの新たな取り組みとして「Youtubeコメント」の分析から おひさまがどんなことに興味を持っているのかを分析中です。

    親コメント約1.8万件のコメントデータをもとにGoogleのColaboを活用し、ワードクラウドを作成し、どんなことに興味を持ったのかを探りました。

    作成したワードクラウドを時系列でみると 楽曲やMVでのパフォーマンスについて→急上昇入りやミリオン入り等の「実績」について→USEN推しリク等日向坂を応援に向けた話について等変化が見られます。

    ※コード作成はGoogle Geminiを活用してます。

    ※日向坂 クリフハンガー等 一部ワードをノイズとして外してます。

    !pip install transformers fugashi ipadic unidic-lite japanize-matplotlib tqdm wordcloud
    import pandas as pd
    from google.colab import auth
    from google.auth import default
    import gspread
    from transformers import pipeline
    import torch
    import matplotlib.pyplot as plt
    import japanize_matplotlib
    from tqdm import tqdm
    from wordcloud import WordCloud
    import fugashi
    import os
    
    # --- 設定 ---
    SHEET_URL = 'コメントを取得したGoogleスプレッドシートのURL'
    TARGET_COLUMN = 'コメント内容'
    DATE_COLUMN = '投稿日(JST)'
    
    # ★ここで除外したい単語を設定します
    EXCLUDE_WORDS = {'日向坂', '日向', 'クリフハンガー', 'クリフ', 'ハンガー', 'MV', '坂'}
    # ------------
    
    # 1. Google認証 & データ読み込み
    print("Google認証とデータ読み込みを行います...")
    auth.authenticate_user()
    creds, _ = default()
    gc = gspread.authorize(creds)
    workbook = gc.open_by_url(SHEET_URL)
    worksheet = workbook.sheet1
    rows = worksheet.get_all_values()
    df = pd.DataFrame(rows[1:], columns=rows[0])
    
    # 2. 日付データの変換
    print("日付データを処理しています...")
    try:
        df['datetime'] = pd.to_datetime(df[DATE_COLUMN], errors='coerce')
        df['date_str'] = df['datetime'].dt.strftime('%Y-%m-%d')
    except:
        pass
    
    # 3. 分析モデル準備
    device = 0 if torch.cuda.is_available() else -1
    print(f"分析モデルをロード中... (モード: {'GPU' if device==0 else 'CPU'})")
    sentiment_analyzer = pipeline(
        "sentiment-analysis",
        model="koheiduck/bert-japanese-finetuned-sentiment",
        tokenizer="koheiduck/bert-japanese-finetuned-sentiment",
        device=device
    )
    
    # 4. 分析実行
    def analyze_sentiment(text):
        if not text: return None
        try:
            return sentiment_analyzer(str(text)[:512])[0]
        except:
            return None
    
    print("全データの感情分析を開始します...")
    tqdm.pandas()
    results = df[TARGET_COLUMN].progress_apply(analyze_sentiment)
    
    df['感情判定'] = results.apply(lambda x: x['label'] if x else None)
    print("分析完了!")
    
    # --- 日別ワードクラウド生成(除外設定付き) ---
    
    print("\nポジティブコメントの日別ワードクラウドを作成します...")
    
    tagger = fugashi.Tagger()
    def extract_nouns(text):
        if not isinstance(text, str): return ""
        words = []
        for word in tagger(text):
            if word.feature.pos1 == '名詞' and word.feature.pos2 not in ['非自立', '代名詞', '数']:
                words.append(word.surface)
        return ' '.join(words)
    
    font_path = os.path.join(os.path.dirname(japanize_matplotlib.__file__), 'fonts', 'ipaexg.ttf')
    
    # ★設定にstopwords(除外リスト)を追加しました
    wc_config = {
        'font_path': font_path,
        'width': 600, 'height': 400,
        'background_color': 'white',
        'regexp': r"[\w']+",
        'colormap': 'spring',
        'collocations': False,
        'stopwords': EXCLUDE_WORDS  # ← ここで除外リストを適用
    }
    
    positive_df = df[df['感情判定'] == 'POSITIVE'].copy()
    grouped = positive_df.groupby('date_str')
    target_dates = sorted(positive_df['date_str'].dropna().unique())
    
    if target_dates:
        MAX_DAYS = 20
        if len(target_dates) > MAX_DAYS:
            print(f"※日数が多いため、コメント数が多い上位 {MAX_DAYS} 日分を表示します。")
            top_dates = positive_df['date_str'].value_counts().nlargest(MAX_DAYS).index
            target_dates = sorted(top_dates)
    
        for date in target_dates:
            day_comments = grouped.get_group(date)[TARGET_COLUMN]
            full_text = " ".join(day_comments.astype(str))
            nouns = extract_nouns(full_text)
            
            # 除外後の単語数が少ない場合はスキップする処理
            # (WordCloud内部でも除外されますが、念のため生成前にチェック)
            if len(nouns) < 10: continue
    
            wc = WordCloud(**wc_config).generate(nouns)
            
            plt.figure(figsize=(8, 5))
            plt.imshow(wc, interpolation='bilinear')
            plt.title(f'{date} のポジティブワード', fontsize=16)
            plt.axis('off')
            plt.show()
    
    print("全処理が完了しました。")