<jupyter_start><jupyter_text>Loading Data<jupyter_code>train, dev, test = load_datasets_unlabeled_test()
display((len(train), len(train[0])))
display((len(dev), len(dev[0])))
display((len(test)))
train_df = pd.DataFrame({'data': train[0], 'target': train[1]})
dev_df = pd.DataFrame({'data': dev[0], 'target': dev[1]})<jupyter_output><empty_output><jupyter_text>Dataset description<jupyter_code>display(train_df.groupby('target').describe())
display(dev_df.groupby('target').describe())
X_train, y_train = train
X_dev, y_dev = dev
X_test = test<jupyter_output><empty_output><jupyter_text>Setting up classifiers<jupyter_code>param_grid = {
    'vect__binary': [True],
    'vect__ngram_range': [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5)],
    'vect__min_df': [1, 3, 5, 7],
    'vect__max_df': [0.95, 0.9, 0.7],
    'clf__random_state': [0],
}

params_list = list(ParameterGrid(param_grid))

vects = [
    CountVectorizer(),
    TfidfVectorizer()
]

clfs = [
#     KNeighborsClassifier(),
#     MultinomialNB(),
#     DecisionTreeClassifier(),
    LogisticRegression(),
    LinearSVC(),
#     SVC(),
#     RandomForestClassifier(),
]
results = []

for vect in vects:
    print(str(vect.__class__))
    for clf in clfs:
        print(str(clf.__class__))
        pipeline = Pipeline([
            ('vect', vect),
            ('clf', clf),
        ])
        for params in params_list:
            print(params)
            pipeline.set_params(**params)
            pipeline.fit(X_train, y_train)
            print_short_eval(pipeline, X_dev, y_dev)
            result0 = eval(pipeline, X_dev, y_dev)
            results.append({
                **result0,
                **params,
            })
results_df = pd.DataFrame(results)
results_df.sort_values(['acc', 'f1'], ascending=False)[:10]<jupyter_output><empty_output><jupyter_text>Trying the best param configuration found<jupyter_code>pipeline = Pipeline([
    ('vect', CountVectorizer(binary=True, ngram_range=(1, 3), max_df=0.95, min_df=5)),
    ('clf', LogisticRegression(random_state=0))
])
pipeline.fit(X_train, y_train)
print_short_eval(pipeline, X_train, y_train)
print_short_eval(pipeline, X_dev, y_dev)
pipeline = Pipeline([
    ('vect', TfidfVectorizer(binary=True, ngram_range=(1, 3), max_df=0.95, min_df=5)),
    ('clf', LinearSVC(random_state=0))
])
pipeline.fit(X_train, y_train)
print_short_eval(pipeline, X_train, y_train)
print_short_eval(pipeline, X_dev, y_dev)<jupyter_output>accuracy	1.00	macro f1	1.00
accuracy	0.92	macro f1	0.92<jupyter_text>The best model found is a LinearSVC using the TfidfVectorizer, we get an accuracy of 0.92  Create file for final submission<jupyter_code>y_test_pred = pipeline.predict(X_test)
submission = y_test_pred
fname = 'datasets/review_polarity_competition/submission.csv'
save_results(fname, submission)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14996471418489768, 'fraction_numerical': 0.022582921665490474, 'mean_word_length': 4.602766798418973, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '218955', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1063, 'n_words': 185, 'path': '04_AprendizajeSupervisado/Lab2.ipynb', 'repo_name': 'dahue/diplodatos', 'size': '2834'}