Commit 90f1c117 authored by Alison Carrera's avatar Alison Carrera
Browse files

Added usage example.

parent 82e15a46
%% 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)))
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment