小红书笔记主题分析

本文介绍如何利用Python库sklearn和pandas对小红书笔记进行爬取和分析。通过词向量将文本转化为向量,运用KMeans进行无监督聚类,将每个笔记归类。
摘要由CSDN通过智能技术生成
# -*- coding: UTF-8 -*-
import numpy as np
import argparse
import random
import pickle as pk
import json


def save_json(file, res):
    """
    保存 dict 到本地json 文件 , 自动创建json
    :param file: json 文件名
    :param res: 数据
    :return:
    """
    with open(file, 'w', encoding='utf-8') as wr:
        json.dump(res, wr, ensure_ascii=False, indent=2)


def load_json(file):
    """
    读取本地json文件,得到dict
    :param file: json 文件名
    :return:
    """
    with open(file, 'r', encoding='utf-8') as reader:
        res = json.load(reader)
    return res


def save_cache(file, ob):
    wr = open(file, 'wb')
    pk.dump(ob, wr)
    wr.close()


def load_cache(file):
    re = open(file, 'rb')
    ob = pk.load(re)
    re.close()
    return ob

def read_vectors(path, topn):  # read top n word vectors, i.e. top is 10000
    lines_num, dim = 0, 0
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值