-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregression.h5.py
170 lines (65 loc) · 1.58 KB
/
regression.h5.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import pandas as pd
# In[2]:
dataset=pd.read_csv("50_Startups AI.csv")
# In[3]:
dataset
# In[4]:
dataset.head(2)
# In[5]:
dataset.isnull().any()
# In[6]:
from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
dataset["State"]=le.fit_transform(dataset["State"])
# In[7]:
dataset.head(2)
# In[8]:
x=dataset.iloc[:,0:4].values
y=dataset.iloc[:,4].values
# In[9]:
from sklearn.preprocessing import OneHotEncoder
one=OneHotEncoder()
z=one.fit_transform(x[:,3:4]).toarray()
x=np.delete(x,3,axis=1)
x=np.concatenate((z,x),axis=1)
# In[10]:
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)
# In[11]:
import keras
from keras.models import Sequential
from keras.layers import Dense
# In[12]:
model=Sequential()
# In[13]:
x_train.shape
# In[14]:
model.add(Dense(units=6,init = "random_uniform",activation="relu"))
# In[15]:
model.add(Dense(units=3,init = "random_uniform",activation="relu"))
# In[16]:
model.add(Dense(units=1,init = "random_uniform"))
# In[17]:
model.compile(optimizer="adam",loss="mse",accuracy=["mse"])
# In[18]:
model.fit(x_train,y_train,batch_size=10,epochs=10)
# In[19]:
y_pred=model.predict(x_test)
# In[20]:
y_pred
# In[21]:
y_test
# In[22]:
from sklearn.metrics import r2_score
accuracy=r2_score(y_test,y_pred)
# In[23]:
accuracy #0.752295052747021 *100=75% is accuracy
# In[25]:
model.save('regressor.h5')
# In[26]:
x_train.shape
# In[ ]: