📘 爬虫+机器学习技术的杭州租房价格预测建模研究/Fenxi.ipynb

Notebook
# 相关性分析 sns.heatmap(df.corr(),vmax=1,annot=True,linewidths=0.5,cbar=False,cmap='YlGnBu',annot_kws={'fontsize':18}) plt.xticks(fontsize=20) plt.yticks(fontsize=20) plt.title('各个因素之间的相关系数',fontsize=20) plt.show()import jieba import collections import re import stylecloud from PIL import Image def draw_WorldCloud(df, pic_name, color='black'): # 将 DataFrame 中的所有文本数据合并为一个字符串 data = ''.join([str(item) for item in df]) # 文本预处理:去除一些无用的字符,只提取出中文 new_data = re.findall('[\u4e00-\u9fa5]+', data, re.S) new_data = "".join(new_data) # 文本分词 seg_list_exact = jieba.cut(new_data, cut_all=True) result_list = [] # 读取停用词库 with open('停用词库.txt', encoding='utf-8') as f: # 可根据需要打开停用词库 con = f.readlines() stop_words = set() for i in con: i = i.replace("\n", "") # 去掉换行符 stop_words.add(i) # 过滤停用词 for word in seg_list_exact: if word not in stop_words and len(word) > 1: result_list.append(word) # 词频统计:获取前100个最高频的词 word_counts = collections.Counter(result_list) word_counts_top = word_counts.most_common(100) print(word_counts_top) # 绘制词云图 stylecloud.gen_stylecloud( text=' '.join(result_list[:500]), # 提取500个词进行绘图 collocations=False, # 是否包括两个单词的搭配(二字组) font_path=r'C:\Windows\Fonts\STXINGKA.TTF', # 设置字体 size=800, # stylecloud 的大小 palette='cartocolors.qualitative.Bold_7', # 调色板 background_color=color, # 背景颜色 # icon_name='fas fa-circle', # 形状的图标名称 gradient='horizontal', # 梯度方向 max_words=2000, # stylecloud 可包含的最大单词数 max_font_size=150, # stylecloud 中的最大字号 stopwords=True, # 布尔值,用于筛除常见禁用词 output_name=f'{pic_name}.png' # 输出图片 ) # 打开图片展示 img = Image.open(f'{pic_name}.png') img.show() # 调用函数进行词云图可视化 draw_WorldCloud(df['房源亮点'], '房源亮点词云图') # 词云图可视化