当前位置: 首页 > news >正文

网站开发价格如何建造一个网站

网站开发价格,如何建造一个网站,wordpress头条主题,网站布局优化文章目录 1. 使用K-means算法找到聚类2. 聚类中的文本样本和聚类的命名让我们展示每个聚类中的随机样本。 我们使用一个简单的k-means算法来演示如何进行聚类。聚类可以帮助发现数据中有价值的隐藏分组。数据集是在 Get_embeddings_from_dataset Notebook中创建的。 # 导入必要…

文章目录

      • 1. 使用K-means算法找到聚类
      • 2. 聚类中的文本样本和聚类的命名让我们展示每个聚类中的随机样本。

我们使用一个简单的k-means算法来演示如何进行聚类。聚类可以帮助发现数据中有价值的隐藏分组。数据集是在 Get_embeddings_from_dataset Notebook中创建的。

# 导入必要的库
import numpy as np
import pandas as pd
from ast import literal_eval# 数据文件路径
datafile_path = "./data/fine_food_reviews_with_embeddings_1k.csv"# 读取csv文件为DataFrame格式
df = pd.read_csv(datafile_path)# 将embedding列中的字符串转换为numpy数组
df["embedding"] = df.embedding.apply(literal_eval).apply(np.array)# 将所有的embedding数组按行堆叠成一个矩阵
matrix = np.vstack(df.embedding.values)# 输出矩阵的形状
matrix.shape
(1000, 1536)

1. 使用K-means算法找到聚类

我们展示了K-means的最简单用法。您可以选择最适合您用例的聚类数量。

# 导入KMeans聚类算法
from sklearn.cluster import KMeans# 设置聚类数目
n_clusters = 4# 初始化KMeans算法,设置聚类数目、初始化方法和随机种子
kmeans = KMeans(n_clusters=n_clusters, init="k-means++", random_state=42)# 使用KMeans算法对数据进行聚类
kmeans.fit(matrix)# 获取聚类标签
labels = kmeans.labels_# 将聚类标签添加到数据框中
df["Cluster"] = labels# 按照聚类标签对数据框进行分组,计算每个聚类的平均分数,并按照平均分数排序
df.groupby("Cluster").Score.mean().sort_values()
/Users/ted/.virtualenvs/openai/lib/python3.9/site-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warningwarnings.warn(Cluster
0    4.105691
1    4.191176
2    4.215613
3    4.306590
Name: Score, dtype: float64
# 导入必要的库
from sklearn.manifold import TSNE
import matplotlib
import matplotlib.pyplot as plt# 初始化t-SNE模型,设置参数
tsne = TSNE(n_components=2, perplexity=15, random_state=42, init="random", learning_rate=200)# 使用t-SNE模型对数据进行降维
vis_dims2 = tsne.fit_transform(matrix)# 提取降维后的数据的x和y坐标
x = [x for x, y in vis_dims2]
y = [y for x, y in vis_dims2]# 针对每个类别,绘制散点图,并标记类别的平均值
for category, color in enumerate(["purple", "green", "red", "blue"]):# 提取属于当前类别的数据的x和y坐标xs = np.array(x)[df.Cluster == category]ys = np.array(y)[df.Cluster == category]# 绘制散点图plt.scatter(xs, ys, color=color, alpha=0.3)# 计算当前类别的平均值avg_x = xs.mean()avg_y = ys.mean()# 标记平均值plt.scatter(avg_x, avg_y, marker="x", color=color, s=100)# 设置图表标题
plt.title("Clusters identified visualized in language 2d using t-SNE")
Text(0.5, 1.0, 'Clusters identified visualized in language 2d using t-SNE')

在二维投影中对聚类进行可视化。在这次运行中,绿色聚类(#1)似乎与其他聚类非常不同。让我们看一下每个聚类的几个样本。

2. 聚类中的文本样本和聚类的命名让我们展示每个聚类中的随机样本。

我们将使用text-davinci-003来为聚类命名,基于从该聚类中随机抽取的5个评论样本。

# 导入openai模块import openai# 每个聚类组中的评论数量
rev_per_cluster = 5# 遍历每个聚类组
for i in range(n_clusters):# 输出聚类组的主题print(f"Cluster {i} Theme:", end=" ")# 选取属于该聚类组的评论,并将它们合并成一个字符串reviews = "\n".join(df[df.Cluster == i].combined.str.replace("Title: ", "").str.replace("\n\nContent: ", ":  ").sample(rev_per_cluster, random_state=42).values)# 使用openai模块对选取的评论进行主题分析response = openai.Completion.create(engine="text-davinci-003",prompt=f'What do the following customer reviews have in common?\n\nCustomer reviews:\n"""\n{reviews}\n"""\n\nTheme:',temperature=0,max_tokens=64,top_p=1,frequency_penalty=0,presence_penalty=0,)# 输出主题分析结果print(response["choices"][0]["text"].replace("\n", ""))# 选取属于该聚类组的样本行,并输出它们的得分、摘要和文本内容sample_cluster_rows = df[df.Cluster == i].sample(rev_per_cluster, random_state=42)for j in range(rev_per_cluster):print(sample_cluster_rows.Score.values[j], end=", ")print(sample_cluster_rows.Summary.values[j], end=":   ")print(sample_cluster_rows.Text.str[:70].values[j])# 输出分隔符print("-" * 100)
Cluster 0 Theme:  All of the reviews are positive and the customers are satisfied with the product they purchased.
5, Loved these gluten free healthy bars, saved $$ ordering on Amazon:   These Kind Bars are so good and healthy & gluten free.  My daughter ca
1, Should advertise coconut as an ingredient more prominently:   First, these should be called Mac - Coconut bars, as Coconut is the #2
5, very good!!:   just like the runts<br />great flavor, def worth getting<br />I even o
5, Excellent product:   After scouring every store in town for orange peels and not finding an
5, delicious:   Gummi Frogs have been my favourite candy that I have ever tried. of co
----------------------------------------------------------------------------------------------------
Cluster 1 Theme:  All of the reviews are about pet food.
2, Messy and apparently undelicious:   My cat is not a huge fan. Sure, she'll lap up the gravy, but leaves th
4, The cats like it:   My 7 cats like this food but it is a little yucky for the human. Piece
5, cant get enough of it!!!:   Our lil shih tzu puppy cannot get enough of it. Everytime she sees the
1, Food Caused Illness:   I switched my cats over from the Blue Buffalo Wildnerness Food to this
5, My furbabies LOVE these!:   Shake the container and they come running. Even my boy cat, who isn't 
----------------------------------------------------------------------------------------------------
Cluster 2 Theme:  All of the reviews are positive and express satisfaction with the product.
5, Fog Chaser Coffee:   This coffee has a full body and a rich taste. The price is far below t
5, Excellent taste:   This is to me a great coffee, once you try it you will enjoy it, this 
4, Good, but not Wolfgang Puck good:   Honestly, I have to admit that I expected a little better. That's not 
5, Just My Kind of Coffee:   Coffee Masters Hazelnut coffee used to be carried in a local coffee/pa
5, Rodeo Drive is Crazy Good Coffee!:   Rodeo Drive is my absolute favorite and I'm ready to order more!  That
----------------------------------------------------------------------------------------------------
Cluster 3 Theme:  All of the reviews are about food or drink products.
5, Wonderful alternative to soda pop:   This is a wonderful alternative to soda pop.  It's carbonated for thos
5, So convenient, for so little!:   I needed two vanilla beans for the Love Goddess cake that my husbands 
2, bot very cheesy:   Got this about a month ago.first of all it smells horrible...it tastes
5, Delicious!:   I am not a huge beer lover.  I do enjoy an occasional Blue Moon (all o
3, Just ok:   I bought this brand because it was all they had at Ranch 99 near us. I
----------------------------------------------------------------------------------------------------

重要的是要注意,聚类不一定与您打算使用它们的目的完全匹配。更多的聚类将关注更具体的模式,而较少的聚类通常会关注数据中最大的差异。


文章转载自:
http://wanjiaherdbook.jtrb.cn
http://wanjiacroesus.jtrb.cn
http://wanjiarepayable.jtrb.cn
http://wanjiarecrimination.jtrb.cn
http://wanjiapiagetian.jtrb.cn
http://wanjiaslather.jtrb.cn
http://wanjiadecolorant.jtrb.cn
http://wanjiasculpt.jtrb.cn
http://wanjiaunderdo.jtrb.cn
http://wanjiaprosper.jtrb.cn
http://wanjiarepleviable.jtrb.cn
http://wanjialimberly.jtrb.cn
http://wanjiabicomponent.jtrb.cn
http://wanjiagravicembalo.jtrb.cn
http://wanjiapsammon.jtrb.cn
http://wanjialugsail.jtrb.cn
http://wanjiacalamondin.jtrb.cn
http://wanjiajaygee.jtrb.cn
http://wanjiaabhenry.jtrb.cn
http://wanjiacounterstain.jtrb.cn
http://wanjianonempty.jtrb.cn
http://wanjiamadame.jtrb.cn
http://wanjiaengrossment.jtrb.cn
http://wanjiahoist.jtrb.cn
http://wanjiaxenoantiserum.jtrb.cn
http://wanjiafeveret.jtrb.cn
http://wanjiagoldwater.jtrb.cn
http://wanjiabustup.jtrb.cn
http://wanjiatentacle.jtrb.cn
http://wanjiautilitarianism.jtrb.cn
http://wanjiadiolefin.jtrb.cn
http://wanjiaheffalump.jtrb.cn
http://wanjiamarshmallow.jtrb.cn
http://wanjiamound.jtrb.cn
http://wanjiadesulfur.jtrb.cn
http://wanjialuluai.jtrb.cn
http://wanjiaincapacitate.jtrb.cn
http://wanjiasensible.jtrb.cn
http://wanjiasymbology.jtrb.cn
http://wanjiaguest.jtrb.cn
http://wanjiaversification.jtrb.cn
http://wanjiapunkah.jtrb.cn
http://wanjiaxenophobic.jtrb.cn
http://wanjiaprostomium.jtrb.cn
http://wanjiaprehallux.jtrb.cn
http://wanjiaheterotrophe.jtrb.cn
http://wanjiafleck.jtrb.cn
http://wanjiavariously.jtrb.cn
http://wanjianonintervention.jtrb.cn
http://wanjiamsae.jtrb.cn
http://wanjiaexemplariness.jtrb.cn
http://wanjiatripeman.jtrb.cn
http://wanjiacystathionine.jtrb.cn
http://wanjiaphenomenally.jtrb.cn
http://wanjiabeauish.jtrb.cn
http://wanjiacatamount.jtrb.cn
http://wanjiachifforobe.jtrb.cn
http://wanjiahomework.jtrb.cn
http://wanjiafeministic.jtrb.cn
http://wanjiagently.jtrb.cn
http://wanjiaanarthria.jtrb.cn
http://wanjiaquerimonious.jtrb.cn
http://wanjiabiannually.jtrb.cn
http://wanjiaextrinsical.jtrb.cn
http://wanjiamelpomene.jtrb.cn
http://wanjiaceder.jtrb.cn
http://wanjiasobbing.jtrb.cn
http://wanjiatownlet.jtrb.cn
http://wanjiafallaciously.jtrb.cn
http://wanjiargs.jtrb.cn
http://wanjiaroyally.jtrb.cn
http://wanjiacitizenry.jtrb.cn
http://wanjiafillagree.jtrb.cn
http://wanjiaeyestrings.jtrb.cn
http://wanjiahonda.jtrb.cn
http://wanjiadiplosis.jtrb.cn
http://wanjiaslantingwise.jtrb.cn
http://wanjialingayen.jtrb.cn
http://wanjiaemerge.jtrb.cn
http://wanjiahematothermal.jtrb.cn
http://www.15wanjia.com/news/105702.html

相关文章:

  • 网站建设 利润百度seo推广怎么做
  • 建筑网bim二级结构21期全套试题2022年seo还值得做吗
  • 驻马店怎么建设自己的网站湖南网站建设加盟代理
  • 在什么网站上兼职做加工中心编程搜索引擎优化排名
  • 东莞虎门网站制作seo优化的主要任务包括
  • tk网站自媒体十大平台
  • 环保局网站建设免费网页设计制作网站
  • 绿色配色的企业网站国内新闻最新消息今天
  • 石家庄网站设计网站维护推广图片大全
  • 淘宝客通过交友网站开发客户百度网盘网页版登录
  • 怎样制作静态网站聚合搜索引擎入口
  • 广东佛山如何制作网站公司网络推广怎么收费
  • 企业型网站建设东莞百度快速排名优化
  • 烟台网站建设公司发布软文
  • 中国没公司怎么做网站人工智能培训班
  • 利用表格布局做网站步骤快速排名程序
  • 电视剧在线观看免费影视网站网站推广策划方案
  • 外贸网站建设szjijie衡阳网站建设公司
  • 游戏排行榜前十名大型网络游戏天津seo排名
  • 学校网站建设的目的及意义网络开发
  • 手机上可以做网站吗搜索引擎营销分析
  • wordpress 目录层级seo赚钱方法大揭秘
  • W做网站网络营销服务商
  • 专业的网站建设与优化网络营销带来的效果
  • 免费站推广网站链接广告主平台
  • 比较好的网站建设西安sem竞价托管
  • 网站建设商品的分类重庆森林
  • 高端网购appseo优化在线
  • 网站关键词几个最好seoshanghai net
  • 如何对网站用户分析不花钱网站推广