许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  Mathematica学习笔记(完整版)

Mathematica学习笔记(完整版)

阅读数 5
点赞 0
article_banner

1. Mathematica 在给出初始聚类中心的情况下进行 Kmeans 聚类

为了避免kmeans得到局部最优解,最好使用随机种子,这里指定聚类中心只适用于特殊情况 如:需要确定的聚类结果等吐槽一下,Mathmatica果然社区还是没有MATLAB完善啊,这个问题我在MATLAB能搜到但是Mathmatica搜不到,当然也有这个问题太简单的原因 😛

首先上结论,使用Method -> {"KMeans", "InitialCentroids" -> {{0, 4}, {3, 3}}来指定初始聚类中心,相关内容文档有,不过就一行我没注意 😦


下面是简单的 实验 -----是否指定初始聚类中心造成的结果变化(没什么内容,没必要看)
使用Kmeans 欧几里得距离 聚类上限10 不指定初始聚类中心 进行聚类

point = {{3, 1}, {3, 2}, {4, 1}, {4, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 
    4}};
l1 = FindClusters[point, 10, Method -> {"KMeans"}, 
  DistanceFunction -> EuclideanDistance]
ListPlot[l1, PlotTheme -> "Detailed", PlotStyle -> PointSize[Large]]

聚类结果图

可以发现,整整聚类出了5个结果,显然不是我们想要的效果,那么下面指定初始聚类中心使用Method -> {"KMeans", "InitialCentroids" -> {{0, 4}, {3, 3}}来指定初始聚类中心
l2 = FindClusters[point, 10, 
  Method -> {"KMeans", "InitialCentroids" -> {{0, 4}, {3, 3}}}, 
  DistanceFunction -> EuclideanDistance]
ListPlot[l2, PlotTheme -> "Detailed", PlotStyle -> PointSize[Large]]

聚类结果

聚出两类,符合预期效果

2.根据llist1的值选取等长list2中的值

  • Pick[list,sel]

        从列表 list 中选取符合条件的元素,其对应于 sel 中的元素为 True.
  • Pick[list,sel,patt]

        从列表 list 中选取符合条件的元素,其对应于 sel 中的元素匹配 patt.
//选取True
Pick[{{3, 1}, {3, 2}, {4, 1}, {4, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 
   4}}, {True, True, True, True, False, False, True, True}]
//选取指定数据
Pick[{{3, 1}, {3, 2}, {4, 1}, {4, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 
   4}}, {True, True, True, True, False, False, True, True}, False]

3. 比较两个等长list,输出一个由true/false组成的list

  • Thread[f[args]]

        将 f 线性作用(thread over)于任意出现在 args 中的列表.
  • Thread[f[args],h]

        将 f 线性作用于出现在 args 中的头部为 h 的任何对象上.
  • Thread[f[args],h,n]

        将 f 线性作用于出现在前 n 项 args 中的头部为 h 的对象上.
tmp1
tmp2
bool = Thread[tmp1 > tmp2]

在这里插入图片描述

4. 绘制风玫瑰图/风向图

答案 借鉴自stackexchange

 r = Table[{2 t Pi/16, RandomReal[{1, 6}]}, {t, 0, 15}];
 
ListPolarPlot[Append[r, r[[1]]], PlotLabel -> "风向图", 
 PlotRange -> {{-7, 7}, {-7, 7}}, PlotMarkers -> Automatic, 
 BaseStyle -> 14, PolarTicks -> {"Direction", Automatic}, 
 Joined -> True, PlotStyle -> {PointSize[Large]}, PolarAxes -> True, 
 PolarGridLines -> Automatic, ImageSize -> Large]

在这里插入图片描述


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空