Skip to content

Commit f66668d

Browse files
committed
updated readme
1 parent 8506540 commit f66668d

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,33 @@ Documentation site: [www.scikitjs.org](https://www.scikitjs.org)
2121
For use with modern bundlers in a frontend application, simply
2222

2323
```bash
24+
npm i @tensorflow/tfjs
2425
npm i scikitjs
2526
```
2627

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.
2830

2931
```js
30-
import { LinearRegression } from 'scikitjs'
32+
import * as tf from '@tensorflow/tfjs'
33+
import * as sk from 'scikitjs'
34+
sk.setBackend(tf)
3135
```
3236

37+
This allows us to build a library that can be used in Deno, Node, and the browser with the same configuration.
3338
### Backend Users
3439

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
3641

3742
```bash
43+
npm i @tensorflow/tfjs-node
3844
npm i scikitjs
3945
```
4046

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-
5047
```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)
5251
```
5352

5453
### Script src
@@ -57,16 +56,21 @@ For those that wish to use script src tags, simply
5756

5857
```html
5958
<script type="module">
59+
import * as tf from 'https://cdn.skypack.dev/@tensorflow/tfjs'
6060
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"
6365
</script>
6466
```
6567

6668
## Simple Example
6769

6870
```js
69-
import { LinearRegression } from 'scikitjs'
71+
import * as tf from '@tensorflow/tfjs-node'
72+
import { setBackend, LinearRegression } from 'scikitjs'
73+
setBackend(tf)
7074

7175
const lr = new LinearRegression({ fitIntercept: false })
7276
const X = [[1], [2]] // 2D Matrix with a single column vector
@@ -124,7 +128,9 @@ Turns into
124128
#### JavaScript
125129

126130
```js
127-
import { LinearRegression } from 'scikitjs'
131+
import * as tf from '@tensorflow/tfjs-node'
132+
import { setBackend, LinearRegression } from 'scikitjs'
133+
setBackend(tf)
128134

129135
let X = [[1], [2]]
130136
let y = [10, 20]
@@ -154,7 +160,9 @@ Turns into
154160
#### JavaScript
155161

156162
```js
157-
import { LinearRegression } from 'scikitjs'
163+
import * as tf from '@tensorflow/tfjs-node'
164+
import { setBackend, LinearRegression } from 'scikitjs'
165+
setBackend(tf)
158166

159167
let X = [[1], [2]]
160168
let y = [10, 20]
@@ -189,7 +197,9 @@ Turns into
189197
#### JavaScript
190198

191199
```js
192-
import { LogisticRegression } from 'scikitjs'
200+
import * as tf from '@tensorflow/tfjs-node'
201+
import { setBackend, LogisticRegression } from 'scikitjs'
202+
setBackend(tf)
193203

194204
let X = [[1], [-1]]
195205
let y = [1, 0]

0 commit comments

Comments
 (0)