Skip to content

Commit

Permalink
more specific name for the base package (shapelets -> shapelets_lts)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohaseeb committed Nov 18, 2017
1 parent 3c5b811 commit 382e00a
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pip install .
```
## Usage ##
```python
from shapelets.classification import LtsShapeletClassifier
from shapelets_lts.classification import LtsShapeletClassifier
# create an LtsShapeletClassifier instance
classifier = LtsShapeletClassifier(
K=20,
Expand Down
48 changes: 31 additions & 17 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,46 @@

from sklearn.metrics import confusion_matrix, classification_report

from shapelets.classification import LtsShapeletClassifier
from shapelets.util import ucr_dataset_loader
from shapelets_lts.classification import LtsShapeletClassifier
from shapelets_lts.util import ucr_dataset_loader

"""
This example expects a dataset in the "UCR Time Series Classification
Archive" format. UCR page (http://www.cs.ucr.edu/~eamonn/time_series_data/)
This example uses dataset from the UCR archive "UCR Time Series Classification
Archive" format.
Follow the instructions at the top of the page UCR page to download the
UCR dataset.
- Follow the instruction on the UCR page
(http://www.cs.ucr.edu/~eamonn/time_series_data/) to download the dataset. You
need to be patient! :)
- Update the vars below to point to the correct dataset location in your
machine.
Update the vars below to point to the correct dataset location in your machine.
Otherwise update _load_train_test_datasets() below to return your own dataset.
"""

ucr_dataset_base_folder = expanduser('~/UCR_TS_Archive_2015')
ucr_dataset_base_folder = expanduser('~/ws/data/UCR_TS_Archive_2015/')
ucr_dataset_name = 'Gun_Point'


def _evaluate_LtcShapeletClassifier(base_folder, dataset_name):
def _load_train_test_datasets():
"""
:return: numpy arrays, train_data, train_labels, test_data, test_labels
train_data and test_data shape is: (n_samples, n_features)
train_labels and test_labels shape is: (n_samples)
"""
return ucr_dataset_loader.load_dataset(
dataset_name=ucr_dataset_name,
dataset_folder=ucr_dataset_base_folder
)


def _evaluate_LtcShapeletClassifier():
# load the data
train_data, train_label, test_data, test_label = (
ucr_dataset_loader.load_dataset(dataset_name, base_folder)
train_data, train_labels, test_data, test_labels = (
_load_train_test_datasets()
)

# create a classifier (the parameter values as per Table1 for the GunPoint
# dataset ). 200 epocs yielded 0.99
# accuracy
# dataset ). 200 epochs yielded 0.99 accuracy
Q = train_data.shape[1]
K = int(0.15 * Q)
L_min = int(0.2 * Q)
Expand All @@ -45,13 +59,13 @@ def _evaluate_LtcShapeletClassifier(base_folder, dataset_name):
)

# train the classifier
classifier.fit(train_data, train_label)
classifier.fit(train_data, train_labels)

# evaluate on test data
prediction = classifier.predict(test_data)
print(classification_report(test_label, prediction))
print(confusion_matrix(test_label, prediction))
print(classification_report(test_labels, prediction))
print(confusion_matrix(test_labels, prediction))


if __name__ == '__main__':
_evaluate_LtcShapeletClassifier(ucr_dataset_base_folder, ucr_dataset_name)
_evaluate_LtcShapeletClassifier()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='shapelets-lts',
version='0.2.2.dev3',
version='0.2.2.dev4',
install_requires=[
'numpy',
'scipy',
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import numpy as np
from sklearn.base import BaseEstimator

from shapelets.network import AggregationLayer
from shapelets.network import CrossEntropyLossLayer
from shapelets.network import LinearLayer
from shapelets.network import Network
from shapelets.network import SigmoidLayer
from shapelets.network import SoftMinLayer
from shapelets.util import utils
from shapelets_lts.network import AggregationLayer
from shapelets_lts.network import CrossEntropyLossLayer
from shapelets_lts.network import LinearLayer
from shapelets_lts.network import Network
from shapelets_lts.network import SigmoidLayer
from shapelets_lts.network import SoftMinLayer
from shapelets_lts.util import utils

"""
This class implements the sklearn estimator interface, so sklearn tools like GridsearchCV can be used
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from shapelets.util import utils
from shapelets_lts.util import utils


class SigmoidLayer:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from shapelets.network import AggregationLayer
from shapelets.util import utils, soft_min_layer_factory
from shapelets_lts.network import AggregationLayer
from shapelets_lts.util import utils, soft_min_layer_factory


def test_forward():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from shapelets.network import CrossEntropyLossLayer
from shapelets.util import utils
from shapelets_lts.network import CrossEntropyLossLayer
from shapelets_lts.util import utils


def test_forward():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import numpy as np

from shapelets.network import LinearLayer
from shapelets.util import utils
from shapelets_lts.network import LinearLayer
from shapelets_lts.util import utils


def test_fc_layer_initialization():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

from shapelets.network import SigmoidLayer
from shapelets.util import utils
from shapelets_lts.network import SigmoidLayer
from shapelets_lts.util import utils


def test_forward():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from shapelets.network import SoftMinLayer
from shapelets.util import utils
from shapelets_lts.network import SoftMinLayer
from shapelets_lts.util import utils


def test_forward():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from shapelets.util import utils
from shapelets_lts.util import utils


def test_get_centroids():
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from shapelets.network.soft_min_layer import SoftMinLayer
from shapelets_lts.network.soft_min_layer import SoftMinLayer


def create_soft_min_layers(sizes):
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 382e00a

Please sign in to comment.