Python01-词云小工具
![](https://i-blog.csdnimg.cn/direct/eeaef255193746ada82fe327815ba542.png)
from wordcloud import WordCloud
import matplotlib.pyplot as plt# 示例文本
text = "监督学习,无监督学习,强化学习,回归分析,分类器,支持向量机,决策树,随机森林,神经网络,卷积神经网络,递归神经网络,长短期记忆网络,梯度下降,反向传播,正则化,交叉验证,超参数调优,损失函数,优化算法,过拟合与欠拟合"# 指定支持中文的字体路径
# 如果你使用的是 Windows 系统,可以使用 "SimHei.ttf"(黑体)字体
# 如果是 macOS,可以使用 "STHeiti Light.ttc"
# font_path = "SimHei.ttf" # 黑体字体路径-Windows系统
font_path = "STHeiti Light.ttc" # 黑体字体路径-macOS系统# 生成词云图
wordcloud = WordCloud(font_path=font_path, # 指定字体路径width=800,height=400,background_color="rgb(233, 192, 66)"
).generate(text)# 展示词云图
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()