tf.js 实战学习笔记
tfvis.render.scatterplot (container,data,opts?)
-
tfjs-vis API 的 CHARTS part
-
绘制散点图(文档见 https://js.tensorflow.org/api_vis/1.4.3/#render.scatterplot)
const series1 = Array(100).fill(0) .map(y => Math.random() * 100 - (Math.random() * 50)) .map((y, x) => ({ x, y, })); const series2 = Array(100).fill(0) .map(y => Math.random() * 100 - (Math.random() * 150)) .map((y, x) => ({ x, y, })); const series = ['First', 'Second']; const data = { values: [series1, series2], series } const surface = { name: 'Scatterplot', tab: 'Charts' }; tfvis.render.scatterplot(surface, data);
-
参数:
- container (HTMLElement|{name: string, tab?: string}|Surface|{drawArea: HTMLElement})
- data (Object)
- values (Point2D[][]|Point2D[]) {x,y}元组的数组(或嵌套数组)。
- series (string[]) 系列名称/标签
- opts (Object) 可选的
- xAxisDomain([number,number]) 被zoomToFit覆盖的 x 轴的区域
- yAxisDomain([number,number]) 被zoomToFit覆盖的 y 轴的区域
- zoomToFit (boolean) 将图表范围设置为仅适合数据。这可能会修改轴比例,但允许将更多数据拟合到视图中。
- seriesColors (string []) 绘制的每个系列的颜色。有效CSS颜色字符串的数组。
- width (number) 图表的宽度(以像素为单位)
- height (number) 图表高度(以像素为单位)
- xLabel (string) xAxis的标签
- yLabel (string) yAxis的标签
- fontSize (number) 以px为单位的fontsize
- xType (‘quantitative’|‘ordinal’|‘nominal’) 将自动设置
- yType (‘quantitative’|‘ordinal’|‘nominal’) 将自动设置
-
返回: Promise
tf.Sequential extends tf.LayersModel
- API Reference 中的 MODELS part 的 Creation 部分
- 具有一叠层的模型,从一个层到另一个层线性地进给。tf.sequential() 是一个工厂函数,可创建 tf.Sequential 的实例。
const model = tf.sequential();
model.add(tf.layers.dense({
units: 1,
inputShape: [2],
activation: 'sigmoid'
}));
model.compile({
loss: tf.losses.logLoss,
optimizer: tf.train.adam(0.1)
});
const inputs = tf.tensor(data.map(p => [p.x, p.y]));
const labels = tf.tensor