-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.py
71 lines (57 loc) · 2.07 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""Console script for elevate_osna."""
import click
import glob
import pickle
import sys
import numpy as np
import pandas as pd
import re
from sklearn.feature_extraction import DictVectorizer
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import KFold
from sklearn.metrics import accuracy_score, classification_report
from . import credentials_path, clf_path
@click.group()
def main(args=None):
"""Console script for osna."""
return 0
@main.command('web')
@click.option('-t', '--twitter-credentials', required=False, type=click.Path(exists=True), show_default=True, default=credentials_path, help='a json file of twitter tokens')
@click.option('-p', '--port', required=False, default=5000, show_default=True, help='port of web server')
def web(twitter_credentials, port):
from .app import app
app.run(host='0.0.0.0', debug=True, port=port)
@main.command('stats')
@click.argument('directory', type=click.Path(exists=True))
def stats(directory):
"""
Read all files in this directory and its subdirectories and print statistics.
"""
print('reading from %s' % directory)
# use glob to iterate all files matching desired pattern (e.g., .json files).
# recursively search subdirectories.
@main.command('train')
@click.argument('directory', type=click.Path(exists=True))
def train(directory):
"""
Train a classifier and save it.
"""
print('reading from %s' % directory)
# (1) Read the data...
#
# (2) Create classifier and vectorizer.
clf = LogisticRegression() # set best parameters
vec = CountVectorizer() # set best parameters
# (3) do cross-validation and print out validation metrics
# (classification_report)
# (4) Finally, train on ALL data one final time and
# train...
# save the classifier
pickle.dump((clf, vec), open(clf_path, 'wb'))
def make_features(df):
## Add your code to create features.
pass
if __name__ == "__main__":
sys.exit(main()) # pragma: no cover