@@ -21,34 +21,33 @@ Documentation site: [www.scikitjs.org](https://www.scikitjs.org)
21
21
For use with modern bundlers in a frontend application, simply
22
22
23
23
``` bash
24
+ npm i @tensorflow/tfjs
24
25
npm i scikitjs
25
26
```
26
27
27
- Usage is similar to other js libraries.
28
+ We depend on the tensorflow library in order to make our calculations fast, but we don't ship it in our bundle.
29
+ We use it as a peer dependency. General usage is as follows.
28
30
29
31
``` js
30
- import { LinearRegression } from ' scikitjs'
32
+ import * as tf from ' @tensorflow/tfjs'
33
+ import * as sk from ' scikitjs'
34
+ sk .setBackend (tf)
31
35
```
32
36
37
+ This allows us to build a library that can be used in Deno, Node, and the browser with the same configuration.
33
38
### Backend Users
34
39
35
- For Node.js users who wish to bind to the Tensorflow C++ library, simply
40
+ For Node.js users who wish to bind to the Tensorflow C++ library, simply import the tensorflow C++ version, and use that as the tf library
36
41
37
42
``` bash
43
+ npm i @tensorflow/tfjs-node
38
44
npm i scikitjs
39
45
```
40
46
41
- But then import the node bindings
42
-
43
- ``` js
44
- import { LinearRegression } from ' scikitjs/node'
45
- ```
46
-
47
- The ` scikitjs/node ` path uses the new "exports" feature of node (which is available in node v13.3+).
48
- If you are using an older version of node, simply pass in the path to the cjs build
49
-
50
47
``` js
51
- import { LinearRegression } from ' scikitjs/dist/cjs/index.js'
48
+ import * as tf from ' @tensorflow/tfjs-node'
49
+ import * as sk from ' scikitjs'
50
+ sk .setBackend (tf)
52
51
```
53
52
54
53
### Script src
@@ -57,16 +56,21 @@ For those that wish to use script src tags, simply
57
56
58
57
``` html
59
58
<script type =" module" >
59
+ import * as tf from ' https://cdn.skypack.dev/@tensorflow/tfjs'
60
60
import * as sk from ' https://cdn.skypack.dev/scikitjs'
61
- // or alternatively you can pull the bundle from unpkg
62
- import * as sk from " https://unpkg.com/scikitjs/dist/web/index.min.js"
61
+ sk .setBackend (tf)
62
+
63
+ // or alternatively you can pull the bundle from unpkg
64
+ // import * as sk from "https://unpkg.com/scikitjs/dist/web index.min.js"
63
65
</script >
64
66
```
65
67
66
68
## Simple Example
67
69
68
70
``` js
69
- import { LinearRegression } from ' scikitjs'
71
+ import * as tf from ' @tensorflow/tfjs-node'
72
+ import { setBackend , LinearRegression } from ' scikitjs'
73
+ setBackend (tf)
70
74
71
75
const lr = new LinearRegression ({ fitIntercept: false })
72
76
const X = [[1 ], [2 ]] // 2D Matrix with a single column vector
@@ -124,7 +128,9 @@ Turns into
124
128
#### JavaScript
125
129
126
130
``` js
127
- import { LinearRegression } from ' scikitjs'
131
+ import * as tf from ' @tensorflow/tfjs-node'
132
+ import { setBackend , LinearRegression } from ' scikitjs'
133
+ setBackend (tf)
128
134
129
135
let X = [[1 ], [2 ]]
130
136
let y = [10 , 20 ]
@@ -154,7 +160,9 @@ Turns into
154
160
#### JavaScript
155
161
156
162
``` js
157
- import { LinearRegression } from ' scikitjs'
163
+ import * as tf from ' @tensorflow/tfjs-node'
164
+ import { setBackend , LinearRegression } from ' scikitjs'
165
+ setBackend (tf)
158
166
159
167
let X = [[1 ], [2 ]]
160
168
let y = [10 , 20 ]
@@ -189,7 +197,9 @@ Turns into
189
197
#### JavaScript
190
198
191
199
``` js
192
- import { LogisticRegression } from ' scikitjs'
200
+ import * as tf from ' @tensorflow/tfjs-node'
201
+ import { setBackend , LogisticRegression } from ' scikitjs'
202
+ setBackend (tf)
193
203
194
204
let X = [[1 ], [- 1 ]]
195
205
let y = [1 , 0 ]
0 commit comments