コード例 #1
0
ファイル: main.py プロジェクト: lbn/kaggle
def test():
    clf = RandomForest
    X_train, y_train = data.split(data.train)
    X_test = data.extract_features(data.test)

    clf.fit(X_train, y_train)
    labels = clf.predict(X_test)
    pd.DataFrame({
        "PassengerId": np.array(data.test["PassengerId"]),
        "Survived": labels
    }).to_csv("submit.csv", index=False)
コード例 #2
0
ファイル: main.py プロジェクト: lbn/kaggle
def test():
    clf = RandomForest
    X_train, y_train = data.split(data.train)
    X_test = data.extract_features(data.test)

    clf.fit(X_train, y_train)
    labels = clf.predict(X_test)
    pd.DataFrame({
        "PassengerId": np.array(data.test["PassengerId"]),
        "Survived": labels
    }).to_csv("submit.csv", index=False)
コード例 #3
0
ファイル: tweet.py プロジェクト: domingobishop/nlp-crawler
def main():
    cfg = keys.cfg_keys()

    tweet_list = guardian.get_guardian_summary(1)

    sentiment = data.classifier.classify(
        data.extract_features(tweet_list[0][0].split()))

    if sentiment == 'negative':
        icon = emoji.emojize(':neutral_face:')
    elif sentiment == 'positive':
        icon = emoji.emojize(':thinking_face:')
    else:
        icon = ''

    api = get_api(cfg)
    tweet = tweet_list[0][0] + ' ' + icon + ' ' + ' #' + tweet_list[
        1] + ' #' + tweet_list[2] + ' #' + tweet_list[3]
    status = api.update_status(status=tweet)
コード例 #4
0
ファイル: main.py プロジェクト: AnujCodeZ/NLP
def predict(tweet, theta):
    x = extract_features(tweet)
    pred = forward(x, theta)
    return ('Positive' if pred > 0.5 else 'Negative')
コード例 #5
0
taxonomies = {'gillet': gillet, 'super': super_category, 'basic': basic_level, 'sub': sub_category}
classifiers = ['knn', 'svm', 'bin_svm', 'bin_knn']

message = """Usage: %s taxonomy classifier features
taxonomy: 'gillet', 'super', 'basic', 'sub'
classifier: 'knn', 'svm', 'bin_svm' or 'bin_knn'
features: 'all', 'reduced', 'auto' (works only with binary classifiers)"""
try:
    _, tax, clf, feature_set = sys.argv
    taxonomy = taxonomies[tax]
    if clf not in classifiers:
        raise Exception
except:
    sys.exit(message % sys.argv[0])

features_, labels_ = extract_features(feature_set)
features = []
labels = []

# Convert an instrument label into the corresponding taxonomy category
def get_category(label):
    for category_, labels in taxonomy.iteritems():
        if label in labels:
            return category_
    return None
# Convert a list of instrument labels into a list of taxonomy categories
def get_categories(labels):
    categories = set([])
    for label in labels:
        category_ = get_category(label)
        if category_ is None:
コード例 #6
0
}
classifiers = ['knn', 'svm', 'bin_svm', 'bin_knn']

message = """Usage: %s taxonomy classifier features
taxonomy: 'gillet', 'super', 'basic', 'sub'
classifier: 'knn', 'svm', 'bin_svm' or 'bin_knn'
features: 'all', 'reduced', 'auto' (works only with binary classifiers)"""
try:
    _, tax, clf, feature_set = sys.argv
    taxonomy = taxonomies[tax]
    if clf not in classifiers:
        raise Exception
except:
    sys.exit(message % sys.argv[0])

features_, labels_ = extract_features(feature_set)
features = []
labels = []


# Convert an instrument label into the corresponding taxonomy category
def get_category(label):
    for category_, labels in taxonomy.iteritems():
        if label in labels:
            return category_
    return None


# Convert a list of instrument labels into a list of taxonomy categories
def get_categories(labels):
    categories = set([])