在这一步先明确这个问题是分类还是回归。通过问题和数据就可以判断出来,数据由 X 和 label 列构成,label 可以一列也可以多列,可以是二进制也可以是实数,当它为二进制时,问题属于分类,当它为实数时,问题属于回归。
第二步:分离数据
为什么需要将数据分成两部分?
用 Training Data 来训练模型,用 Validation Data 来检验这个模型的表现,不然的话,通过各种调节参数,模型可以在训练数据集上面表现的非常出色,但是这可能会是过拟合,过拟合就是太依赖现有的数据了,拟合的效果特别好,但是只适用于训练集,以致于来一个新的数据,就不知道该预测成什么了。所以需要有 Validation 来验证一下,看这个模型是在那里自娱自乐呢,还是真的表现出色。
ECMAScript 6, also known as ECMAScript 2015, is the latest version of the ECMAScript standard. ES6 is a significant update to the language, and the first update to the language since ES5 was standardized in 2009. Implementation of these features in major JavaScript engines is underway now.
See the ES6 standard for full specification of the ECMAScript 6 language.
Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both statement block bodies as well as expression bodies which return the value of the expression. Unlike functions, arrows share the same lexical this as their surrounding code.
// Expression bodiesvar odds =evens.map(v=> v +1);
var nums =evens.map((v, i) => v + i);
var pairs =evens.map(v=> ({even: v, odd: v +1}));
// Statement bodiesnums.forEach(v=> {
if (v %5===0)
fives.push(v);
});
// Lexical thisvar bob = {
_name:"Bob",
_friends: [],
printFriends() {
this._friends.forEach(f=>console.log(this._name+" knows "+ f));
}
}
ES6 classes are a simple sugar over the prototype-based OO pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.
Object literals are extended to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods, making super calls, and computing property names with expressions. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.
Template strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.
// Basic literal string creation`In JavaScript '\n' is a line-feed.`// Multiline strings`In JavaScript this is not legal.`// String interpolationvar name ="Bob", time ="today";
`Hello ${name}, how are you ${time}?`// Construct an HTTP request prefix is used to interpret the replacements and constructionPOST`http://foo.org/bar?a=${a}&b=${b} Content-Type: application/json X-Credentials: ${credentials} { "foo": ${foo}, "bar": ${bar}}`(myOnReadyStateChangeHandler);
Destructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo["bar"], producing undefined values when not found.
// list matchingvar [a, , b] = [1,2,3];
// object matchingvar { op: a, lhs: { op: b }, rhs: c }
=getASTNode()
// object matching shorthand// binds `op`, `lhs` and `rhs` in scopevar {op, lhs, rhs} =getASTNode()
// Can be used in parameter positionfunctiong({name: x}) {
console.log(x);
}
g({name:5})
// Fail-soft destructuringvar [a] = [];
a ===undefined;
// Fail-soft destructuring with defaultsvar [a =1] = [];
a ===1;
Callee-evaluated default parameter values. Turn an array into consecutive arguments in a function call. Bind trailing parameters to an array. Rest replaces the need for arguments and addresses common cases more directly.
functionf(x, y=12) {
// y is 12 if not passed (or passed as undefined)return x + y;
}
f(3) ==15
functionf(x, ...y) {
// y is an Arrayreturn x *y.length;
}
f(3, "hello", true) ==6
functionf(x, y, z) {
return x + y + z;
}
// Pass each elem of array as argumentf(...[1,2,3]) ==6
Iterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize for..in to custom iterator-based iteration with for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.
let fibonacci = {
[Symbol.iterator]() {
let pre =0, cur =1;
return {
next() {
[pre, cur] = [cur, pre + cur];
return { done:false, value: cur }
}
}
}
}
for (var n of fibonacci) {
// truncate the sequence at 1000if (n >1000)
break;
console.log(n);
}
Iteration is based on these duck-typed interfaces (using TypeScript type syntax for exposition only):
Generators simplify iterator-authoring using function* and yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional next and throw. These enable values to flow back into the generator, so yield is an expression form which returns a value (or throws).
Note: Can also be used to enable ‘await’-like async programming, see also ES7 await proposal.
var fibonacci = {
[Symbol.iterator]:function*() {
var pre =0, cur =1;
for (;;) {
var temp = pre;
pre = cur;
cur += temp;
yield cur;
}
}
}
for (var n of fibonacci) {
// truncate the sequence at 1000if (n >1000)
break;
console.log(n);
}
The generator interface is (using TypeScript type syntax for exposition only):
Non-breaking additions to support full Unicode, including new Unicode literal form in strings and new RegExp u mode to handle code points, as well as new APIs to process strings at the 21bit code points level. These additions support building global apps in JavaScript.