Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

线性图

机器学习通常使用线形图来展示关系。

线形图展示了线性函数的值: 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=" + 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=" + slope + " Intercept=" + intercept};

// 使用 Plotly 展示
Plotly.newPlot("myPlot", data, layout);
自己尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.