-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_training.py
41 lines (27 loc) · 1.47 KB
/
mod_training.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
from sklearn.metrics import fbeta_score
from sklearn.metrics import accuracy_score
from sklearn.metrics import precision_recall_fscore_support, classification_report, confusion_matrix
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
from sklearn.utils.class_weight import compute_sample_weight
# Split the 'features' and 'income' data into training and testing sets
def xy_split(data, target, random_state):
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data,
target,
test_size = 0.2,
random_state = random_state)
# Show the results of the split
#print("Training set has {} samples.".format(X_train.shape[0]))
#print("Testing set has {} samples.".format(X_test.shape[0]))
return X_train, X_test, y_train, y_test
def train_predict(data, target, clf, beta):
X_train, X_test, y_train, y_test = xy_split(data, target, 0)
sample_weights = compute_sample_weight('balanced', y_train, indices=None)
clf = clf
clf_name = clf.__class__.__name__
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
return clf, y_test, y_pred
if __name__ == '__main__':
print('No direct calling of this module.')