0%

1.Linear Regression 预测 2.Logistic Regression 分类 3.Softmax Regres 分类

最小二乘法

  • 计算所有样本误差的平均 [代价函数]
  • 使用最优化方法寻找数据的最佳函数匹配\(a+b=c\)

两种图片引用

Elegant in code, simple in core

a pic

1.find( (element, index, array)=>{} )

返回数组中满足提供的测试函数的第一个元素的值。

1
2
3
4
5
var arr = [{id:1,name:"张三"},{id:2,name:"王五"}]
arr.find(item => {
return item.id === 1 //
})
查询结果:{id:1,name:"张三"}

2.findIndex( (element, index, array)=>{} )

返回数组中满足提供的测试函数的第一个元素的索引

1
2
3
4
5
6
7
8
arr.findIndex(item => {
return item.id === 1
})
查询得到下标为:0
arr.findIndex(item => {
return item.id === 2
})
试图查找id为2的记录,不存在返回-1

3.map( (currentValue, index, array)=>{} )

方法通过对每个数组元素执行函数来创建新数组,不会改变原数组

1
2
3
4
5
6
var numbers1 = [45, 4, 9, 16, 25];
var numbers2 = numbers1.map(myFunction);
// 参数(项目值,项目索引,数组本身)
function myFunction(value, index, array) {
return value * 2;
}

注意操作json数组的时候,使用运算符 ...来避免地址引用导致修改原数组。 #### 4.filter()

创建一个包含通过测试的数组元素的新数组.

1
2
3
4
5
6
var numbers = [45, 4, 9, 16, 25];
var over18 = numbers.filter(myFunction);

function myFunction(value, index, array) {
return value > 18;
}

5.forEach

常用数组操作方法

forEach被调用时不会改变调用它的数组,而回调函数可能会改变新数组,例如:

1
2
3
4
5
6
7
8
9
10
var replaceSpace = function(s) {
let a = s.split('')
a.forEach((item,index,b)=>{
if(item===' '){
b[index] = '%20' //这里改变原数组
}
})
return a.join('')
};
console.log(replaceSpace("We are happy."))

1.null值

2.undefined

3.NaN

1
2
3
if(isNaN(tmp)){
console.log(123)
}

1.按照年份这个字段查询,查不出数据

从CSV导入到数据中,年份是数字在数据库类型默认为int32,需要改回model中定义的String类型

在shell中执行以下更改命令:

1
2
3
db.getCollection('employment_rate').find({}).forEach(function(doc){
db.employment_rate.update({_id:doc._id},{$set:{year:doc.year.toString()}});
})

2.$match根据变量查找记录,当需要查找所有记录

例如:

1
2
3
4
5
6
7
let selectYear = req.query.selectYear
if(selectYear == "all"){
selectYear = /./
}
$match: {
year: selectYear
}
目前的做法是使用正则表达式查询所有记录,如上selectYear = /./ ##3.数据库批量修改一个字段的值

Numpy使用

1.从文件中加载数据

记录 mongose 使用过程中遇到的应用场景

阅读全文 »