-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsimple_mtask_classification.py
More file actions
117 lines (86 loc) · 3.04 KB
/
simple_mtask_classification.py
File metadata and controls
117 lines (86 loc) · 3.04 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import os
import nnetsauce as ns
import numpy as np
from sklearn.datasets import load_breast_cancer, load_wine, load_digits, load_iris, make_classification
from sklearn.linear_model import ElasticNet, LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn import metrics
from time import time
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
# dataset no. 1 ----------
print(" \n breast cancer dataset ----- \n")
breast_cancer = load_breast_cancer()
Z = breast_cancer.data
t = breast_cancer.target
X_train, X_test, y_train, y_test = train_test_split(Z, t, test_size=0.2,
random_state=123+2*10)
# Linear Regression is used
regr = RandomForestRegressor()
fit_obj = ns.SimpleMultitaskClassifier(regr)
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
#print(fit_obj.score(X_test, y_test))
start = time()
preds = fit_obj.predict(X_test)
print(f"Elapsed {time() - start}")
print("preds", preds)
print(metrics.classification_report(preds, y_test))
# dataset no. 4 ----------
print(" \n wine dataset ----- \n")
dataset = load_wine()
Z = dataset.data
t = dataset.target
#np.random.seed(123)
X_train, X_test, y_train, y_test = train_test_split(Z, t, test_size=0.2,
random_state=123+2*10)
# Linear Regression is used
regr = RandomForestRegressor()
fit_obj = ns.SimpleMultitaskClassifier(regr)
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
#print(fit_obj.score(X_test, y_test))
start = time()
preds = fit_obj.predict(X_test)
print(f"Elapsed {time() - start}")
print(metrics.classification_report(preds, y_test))
# dataset no. 3 ----------
print(" \n iris dataset ----- \n")
dataset = load_iris()
Z = dataset.data
t = dataset.target
#np.random.seed(123)
X_train, X_test, y_train, y_test = train_test_split(Z, t, test_size=0.2,
random_state=123+2*10)
# Linear Regression is used
regr = RandomForestRegressor()
fit_obj = ns.SimpleMultitaskClassifier(regr)
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
#print(fit_obj.score(X_test, y_test))
start = time()
preds = fit_obj.predict(X_test)
print(f"Elapsed {time() - start}")
print(metrics.classification_report(preds, y_test))
# dataset no. 2 ----------
print(" \n digits dataset ----- \n")
dataset = load_digits()
Z = dataset.data
t = dataset.target
#np.random.seed(123)
X_train, X_test, y_train, y_test = train_test_split(Z, t, test_size=0.2,
random_state=123+2*10)
# Linear Regression is used
regr = RandomForestRegressor()
fit_obj = ns.SimpleMultitaskClassifier(regr)
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
#print(fit_obj.score(X_test, y_test))
start = time()
preds = fit_obj.predict(X_test)
print(f"Elapsed {time() - start}")
print(metrics.classification_report(preds, y_test))