https://github.com/aajanki/sequence-classification
Scikit-learn compatible sequence classifier
https://github.com/aajanki/sequence-classification
machine-learning scikit-learn sequence-classification
Last synced: 13 days ago
JSON representation
Scikit-learn compatible sequence classifier
- Host: GitHub
- URL: https://github.com/aajanki/sequence-classification
- Owner: aajanki
- License: other
- Created: 2018-01-14T15:53:16.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-15T19:35:34.000Z (about 8 years ago)
- Last Synced: 2025-04-25T08:43:30.112Z (11 months ago)
- Topics: machine-learning, scikit-learn, sequence-classification
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 23
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sequence classifier with a scikit-learn interface
[](https://travis-ci.org/aajanki/sequence-classification)
[](https://badge.fury.io/py/sklearn-sequence-classifiers)
[](http://spiceprogram.org/oss-sponsorship/)
Convolutional neural network sequence classifier in the spirit of [`[1]`](#references). Wraps a Keras implementation as a scikit-learn classifier.
## Software requirements
* Python (2.7 or >= 3.5)
* scikit-learn (tested on 0.19)
* Keras (tested on 2.0.5, with the Theano 0.9.0 backend)
## Installation
[Install Keras](https://keras.io/#installation). This has been tested on the Theano backend, should work on other backends, too.
```
pip3 install --user sklearn-sequence-classifiers
```
Installing from the source code:
```
git clone git@github.com:aajanki/sequence-classification.git
cd sequence-classification
python3 setup.py install --user
```
## Running tests
```
python3 setup.py test
```
## Usage example
Predicting IMDB review sentiments.
```python
from keras.datasets import imdb
from keras.preprocessing import sequence
from sequence_classifiers import CNNSequenceClassifier
maxlen = 400
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=5000)
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
clf = CNNSequenceClassifier(epochs=2)
clf.fit(x_train, y_train)
print(clf.score(x_test, y_test))
```
## License
BSD
## References
[1] Yoon Kim: [Convolutional Neural Networks for Sentence Classification](https://arxiv.org/abs/1408.5882)