我正在尝试在本地javascript文件中使用gression.js。我正在使用CDN来获取gression.js。
<script src='https://cdnjs.cloudflare.com/ajax/libs/regression/1.4.0/regression.min.js'></script>
当我尝试在本地javascript文件中使用回归时,
``data is an array of coordinate pairs, similar to the example [here](https://github.com/Tom-Alexander/regression-js)
let linearRegression = regression.linear(data);
但是当我尝试显示回归方程式时,我得到一个错误。我已经知道回归被视为一个函数,但是我不确定为什么。当我使用CDN时,有人知道我如何使用回归js方法吗?
<head>
<!--MetaData-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Security History</title>
<!--Stylesheets-->
<link rel='stylesheet' href='{% static "interface/common.css" %}' />
<link rel='stylesheet' href='{% static "interface/edit_style.css" %}' />
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<!--Scripts-->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<!--<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.15.0/popper.min.js'></script>-->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/regression/1.4.0/regression.min.js'></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src='{% static "interface/historyGraphing.js" %}'></script>
</head>
答案 0 :(得分:1)
我不熟悉该库,但是好像您应该在网络上使用它一样:
let linearRegression = regression('linear', [[0, 1], [32, 67], [12, 79]]);
console.log(linearRegression)
<script src='https://cdnjs.cloudflare.com/ajax/libs/regression/1.4.0/regression.min.js'></script>
他们的文档引用了CDN托管的库,但它们并非100%清除。该库的最新CDN托管版本是1.4.0版。如果您看一下the 1.4.0 docs,它们会像上面的我的例子一样。
最新版本(2.0.1)的docs that you likely found假定您将导入模块。