Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
张 建国
onn在线训练
Commits
90f1c117
Commit
90f1c117
authored
Jun 13, 2019
by
Alison Carrera
Browse files
Added usage example.
parent
82e15a46
Changes
1
Show whitespace changes
Inline
Side-by-side
ONN_Usage_Example.ipynb
0 → 100644
View file @
90f1c117
%% Cell type:markdown id: tags:
#Installing Dependencies
%% Cell type:code id: tags:
```
!pip install onn
```
%% Cell type:markdown id: tags:
##Importing Dependencies
%% Cell type:code id: tags:
```
from onn.OnlineNeuralNetwork import ONN
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
```
%% Cell type:markdown id: tags:
## Initializing Network
%% Cell type:code id: tags:
```
onn_network = ONN(features_size=10, max_num_hidden_layers=5, qtd_neuron_per_hidden_layer=40, n_classes=10)
```
%% Cell type:markdown id: tags:
##Creating Fake Classification Dataset
%% Cell type:code id: tags:
```
X, Y = make_classification(n_samples=50000, n_features=10, n_informative=4, n_redundant=0, n_classes=10,
n_clusters_per_class=1, class_sep=3)
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=42, shuffle=True)
```
%% Cell type:markdown id: tags:
##Learning and predicting at the same time
%% Cell type:code id: tags:
```
for i in range(len(X_train)):
onn_network.partial_fit(np.asarray([X_train[i, :]]), np.asarray([y_train[i]]))
if i % 1000 == 0:
predictions = onn_network.predict(X_test)
print("Online Accuracy: {}".format(accuracy_score(y_test, predictions)))
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment