forked from commit-live-students/Machine-Learning-Case-Study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_model.py
More file actions
29 lines (23 loc) · 957 Bytes
/
build_model.py
File metadata and controls
29 lines (23 loc) · 957 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
28
29
#Importing necessary packages in Python
import pickle
import os
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import randint as sp_randint
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
X_train, y_train = pickle.load(open(ROOT_DIR + "/data/german_train.p", "rb"))
def build():
creditClf = RandomForestClassifier(n_estimators=20, random_state=1)
creditClf.fit(X=X_train, y=y_train)
return creditClf
def verify(clf, X, y):
y_pred = clf.predict(X)
print("=====================")
print('Accuracy score: %.2f' % accuracy_score(y, y_pred))
print('Classification scores: \n', classification_report(y, y_pred))
if __name__ == "__main__":
creditClf = build()
verify(creditClf, X_train, y_train)