def train_lda(data): model = LinearDiscriminantAnalysis() print('#### Linear Discriminant Analysis ####') scores = cross_val_score(model, data[0], data[1], cv=5, scoring='f1_macro', n_jobs=8) print('f1 macro %s' % str(scores)) scores = cross_val_score(model, data[0], data[1], cv=5, scoring='precision_macro', n_jobs=8) print('precision macro %s' % str(scores)) scores = cross_val_score(model, data[0], data[1], cv=5, scoring='recall_macro', n_jobs=8) print('recall macro %s' % str(scores)) model.fit(data[0], data[1]) write_model(model.intercept_, model.coef_, 'lda')
def train_regression(data): model = LogisticRegression(class_weight='balanced', solver='liblinear', max_iter=4000, penalty='l2', random_state=1) print('#### Logistic Regression ####') scores = cross_val_score(model, data[0], data[1], cv=5, scoring='f1_macro', n_jobs=8) print('f1 macro %s' % str(scores)) scores = cross_val_score(model, data[0], data[1], cv=5, scoring='precision_macro', n_jobs=8) print('precision macro %s' % str(scores)) scores = cross_val_score(model, data[0], data[1], cv=5, scoring='recall_macro', n_jobs=8) print('recall macro %s' % str(scores)) model.fit(data[0], data[1]) write_model(model.intercept_, model.coef_, 'regression')