-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomForestClassification.py
More file actions
73 lines (43 loc) · 1.53 KB
/
randomForestClassification.py
File metadata and controls
73 lines (43 loc) · 1.53 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from parsl import load, python_app
from parsl.configs.local_threads import config
load(config)
import pandas as pd
import numpy as np
import time
df = pd.read_csv("/home/amanda/Downloads/bill_authentication.csv")
from parsl.config import Config
from parsl.executors.threads import ThreadPoolExecutor
maxThreads = 10
local_threads = Config(
executors=[
ThreadPoolExecutor(
max_threads=maxThreads,
label='local_threads'
)
]
)
@python_app
def rfClassifier(estimators):
import pandas as pd
import numpy as np
dataset = df
dataset.head()
X = dataset.iloc[:, 0:4].values
y = dataset.iloc[:, 4].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators=estimators, random_state=0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
#print(confusion_matrix(y_test,y_pred))
#print(classification_report(y_test,y_pred))
#print(accuracy_score(y_test, y_pred))
return str(confusion_matrix(y_test,y_pred)) + '\n' +(classification_report(y_test,y_pred)) + '\n' + str(accuracy_score(y_test, y_pred))
#print(rfClassifier().result())