Wolfram 机器学习 | 应用示例

在代码中点击并按下
+
,即可编辑并运行任何代码。
机器学习与神经网络。 从生产级经典机器学习到现代人工智能,深度集成统计分析、可视化、图像处理等功能,助您构建智能系统。

使用和训练分类器

使用预先训练的分类器识别图像:
Run
In[]:=
Classify"NotablePerson",

对文本使用预训练的语言分类器:
Run
In[]:=
Classify["Language","the house is blue","la maison est bleue","la casa es azul","das Haus ist blau","房子是蓝色的","المنزل باللون الأزرق","будинок синій"]
预训练模型还应用于许多其他函数中:
Run
In[]:=
ImageIdentify
,
,
,SpecificityGoal->"Low"
Out[]=

vertebrate
,
domestic dog
,
lizard

使用高级代码训练自定义分类器:
Run
topicClassifier=​​Classify​​"the cat is grey"->
,​​"my cat is fast"->
,​​"this dog is scary"->
,​​"the big dog"->
​​
使用您训练好的模型:
Run
topicClassifier[{"nice cat","what a dog"}]

聚类分析

在数据中发现聚类:
Run
ListPlotFindClusters
GaussianDisks

指定方法和其他选项以获得更精确的控制:
Run
ListPlotFindClusters
Rings
,Method->"DBSCAN"
指定上下文为图,分析聚类:
Run
CommunityGraphPlot[ExampleData[{"NetworkGraph","JazzMusicians"}]]
分析图像中的组件:
Run
ClusteringComponents
,7//Colorize

降维

颜色函数展示了数据结构可以嵌入到低维空间中:
Run
ListPointPlot3D
Higher Dimension Data
,​​ColorFunction->Hue0.5-0.5
Total[
2
{#1,#2}
]
&,​​ColorFunctionScaling->False,​​
Options

为该数据集创建降维函数:
Run
dr=DimensionReduction
Higher Dimension Data
,Method->"Isomap"
将降维函数应用于数据:
Run
ListPlotdr
Higher Dimension Data
,ColorFunction(Hue[0.5#1]&)

检测异常数据

从经典数据集中获取信息:
Run
In[]:=
irisdata=ResourceData["Sample Data: Fisher's Irises"][All,{"PetalLength","SepalWidth"},QuantityMagnitude];
创建异常检测函数:
Run
detector=AnomalyDetection[irisdata]
使用检测器函数查找数据集中的异常值:
Run
anomalies=FindAnomalies[detector,irisdata]
可视化数据和决策边界:
Run
Show​​ContourPlotdetector[{x,y},"RarerProbability"],{x,-1,9},{y,1,5},
Options
,​​ListPlot{irisdata,anomalies},
Options
​​

插补缺失数据

通过删除数据集中的部分信息来模拟缺失数据:
Run
incompletedata=
Data
/.{x_/;4<x<5,y_}:>{x,Missing[]};​​ListPlot[incompletedata]
训练分布模型以预测缺失值:
Run
{nonmissingdata,missingdata}=GatherBy[incompletedata,MemberQ[_Missing]];​​ld=LearnDistribution[nonmissingdata]
合成缺失值并绘制结果:
Run
synthesized=SynthesizeMissingValues[ld,missingdata];​​ListPlot[{incompletedata,synthesized}]

训练和研究神经网络

获取用于分类的经典数据集:
Run
In[]:=
trainingdata=ResourceData["MNIST","TrainingData"];​​testdata=ResourceData["MNIST","TestData"];​​SeedRandom[1234];​​RandomSample[trainingdata,5]
Out[]=

9,
4,
0,
2,
5
在数据上训练模型(运算可能需要较长时间):
Run
In[]:=
trainedNet=NetTrain[NetModel["LeNet"],trainingdata,MaxTrainingRounds->2]
Out[]=
NetChain
Inputport:
image
Outputport:
class
Data not saved. Save now

查看训练后的网络性能:
Run
NetMeasurements[trainedNet,testdata,{"Accuracy","ConfusionMatrixPlot"}]
Out[]=
0.9889,
actual class
​
predicted class


计算机视觉

自然语言处理

语音分析