-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpie.py
More file actions
27 lines (24 loc) · 920 Bytes
/
pie.py
File metadata and controls
27 lines (24 loc) · 920 Bytes
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
import pandas as pd
from pypastry.experiment import Experiment
from pypastry.predictors.document import DocumentClassifier
from sklearn.datasets import fetch_20newsgroups
from sklearn.metrics import f1_score, make_scorer
from sklearn.model_selection import StratifiedKFold
def get_experiment():
# dataset = pd.read_csv('test_dataset.csv')
categories = [
'alt.atheism',
'talk.religion.misc',
]
dataset_bunch = fetch_20newsgroups(subset='train', categories=categories)
dataset = pd.DataFrame({
'text': dataset_bunch['data'],
'relevant': dataset_bunch['target'],
})
# label_column = dataset.columns[1]
predictor = DocumentClassifier('text')
cross_validator = StratifiedKFold(n_splits=2)
scorer = make_scorer(f1_score)
label_column = 'relevant'
print(dataset)
return Experiment(dataset, label_column, predictor, cross_validator, scorer)