-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
92 lines (62 loc) · 3.09 KB
/
model.py
File metadata and controls
92 lines (62 loc) · 3.09 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
# A set of sample self contained examples from sklearn native examples
from dqnn import *
# Example 1: Binary Classification - Breast Cancer
# print("BINARY CLASSIFICATION - Breast Cancer Dataset")
# from sklearn.datasets import load_breast_cancer
# from sklearn.model_selection import train_test_split
# from sklearn.preprocessing import StandardScaler
# X, y = load_breast_cancer(return_X_y=True)
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# scaler = StandardScaler()
# X_train = scaler.fit_transform(X_train)
# X_test = scaler.transform(X_test)
# X_train = torch.FloatTensor(X_train)
# y_train = torch.FloatTensor(y_train)
# X_test = torch.FloatTensor(X_test)
# y_test = torch.FloatTensor(y_test)
# dqnn = DQNN(X_train, y_train, X_test, y_test, task_type='classification')
# episode_rewards = dqnn.train(episodes=5, max_steps_per_episode=3)
# Example 2: Multiclass Classification - Iris
# print("MULTICLASS CLASSIFICATION - Iris Dataset")
# from sklearn.datasets import load_iris
# X, y = load_iris(return_X_y=True)
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# scaler = StandardScaler()
# X_train = scaler.fit_transform(X_train)
# X_test = scaler.transform(X_test)
# X_train = torch.FloatTensor(X_train)
# y_train = torch.LongTensor(y_train)
# X_test = torch.FloatTensor(X_test)
# y_test = torch.LongTensor(y_test)
# dqnn_mc = DQNN(X_train, y_train, X_test, y_test, task_type='classification')
# episode_rewards_mc = dqnn_mc.train(episodes=5, max_steps_per_episode=3)
# # Example 3: Regression - Diabetes
# print("REGRESSION - Diabetes Dataset")
# from sklearn.datasets import load_diabetes
# X, y = load_diabetes(return_X_y=True)
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# scaler = StandardScaler()
# X_train = scaler.fit_transform(X_train)
# X_test = scaler.transform(X_test)
# X_train = torch.FloatTensor(X_train)
# y_train = torch.FloatTensor(y_train)
# X_test = torch.FloatTensor(X_test)
# y_test = torch.FloatTensor(y_test)
# dqnn_reg = DQNN(X_train, y_train, X_test, y_test, task_type='regression')
# episode_rewards_reg = dqnn_reg.train(episodes=5, max_steps_per_episode=3)
# print("All tasks completed! Check the Streamlit dashboard for results.")
# Example 4: Complex Multiclass classification task
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
X, y = make_classification(n_samples=1500, n_features=40, n_informative=10, n_redundant=30, n_classes=5,random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
X_train = torch.FloatTensor(X_train)
y_train = torch.FloatTensor(y_train)
X_test = torch.FloatTensor(X_test)
y_test = torch.FloatTensor(y_test)
dqnn_complex = DQNN(X_train, y_train, X_test, y_test, task_type='classification')
episode_rewards_complex = dqnn_complex.train(episodes=30, max_steps_per_episode=5)