線性圖
機器學習經常使用折線圖來顯示關係。
折線圖顯示線性函式的值:y = ax + b
重要關鍵詞
- 線性(直線)
- 斜率(角度)
- 截距(起始值)
線性
線性意味著直線。線性圖是一條直線。
圖包含兩個軸:x軸(水平)和y軸(垂直)。
示例
const xValues = [];
const yValues = [];
// 生成值
for (let x = 0; x <= 10; x += 1) {
xValues.push(x);
yValues.push(x);
}
// 定義資料
const data = [{
x: xValues,
y: yValues,
mode: "lines"
}];
// 定義佈局
const layout = {title: "y = x"};
// 使用 Plotly 顯示
Plotly.newPlot("myPlot", data, layout);
自己動手試一試 »
斜率
斜率是圖的角度。
斜率是線性圖中的a值
y = ax
在此示例中,斜率 = 1.2
示例
let slope = 1.2;
const xValues = [];
const yValues = [];
// 生成值
for (let x = 0; x <= 10; x += 1) {
xValues.push(x);
yValues.push(x * slope);
}
// 定義資料
const data = [{
x: xValues,
y: yValues,
mode: "lines"
}];
// 定義佈局
const layout = {title: "斜率=" + slope};
// 使用 Plotly 顯示
Plotly.newPlot("myPlot", data, layout);
自己動手試一試 »
截距
截距是圖的起始值。
截距是線性圖中的b值
y = ax + b
在此示例中,斜率 = 1.2 且截距 = 7
示例
let slope = 1.2;
let intercept = 7;
const xValues = [];
const yValues = [];
// 生成值
for (let x = 0; x <= 10; x += 1) {
xValues.push(x);
yValues.push(x * slope + intercept);
}
// 定義資料
const data = [{
x: xValues,
y: yValues,
mode: "lines"
}];
// 定義佈局
const layout = {title: "斜率=" + slope + " 截距=" + intercept};
// 使用 Plotly 顯示
Plotly.newPlot("myPlot", data, layout);
自己動手試一試 »