|
194 | 194 |
|
195 | 195 | # Plot decision functions |
196 | 196 |
|
197 | | -# Data on which to plot source |
198 | | -x_min, x_max = Xs[:, 0].min() - 1, Xs[:, 0].max() + 1 |
199 | | -y_min, y_max = Xs[:, 1].min() - 1, Xs[:, 1].max() + 1 |
200 | | -xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), |
201 | | - np.arange(y_min, y_max, plot_step)) |
202 | | -# Plot source model |
203 | | -Z = clf_source.predict(np.c_[xx.ravel(), yy.ravel()]) |
204 | | -Z = Z.reshape(xx.shape) |
205 | | -fig, ax = plt.subplots(nrows=1, ncols=len(methods) + 1, figsize=(30, 3)) |
206 | | -ax[0].contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8) |
207 | | -ax[0].scatter(Xs[0, 0], Xs[0, 1], |
208 | | - marker='o', |
209 | | - edgecolor='black', |
210 | | - color='white', |
211 | | - label='source data', |
212 | | - ) |
213 | | -ax[0].scatter(Xs[:ns_perclass, 0], Xs[:ns_perclass, 1], |
214 | | - marker='o', |
215 | | - edgecolor='black', |
216 | | - color='blue', |
217 | | - ) |
218 | | -ax[0].scatter(Xs[ns_perclass:, 0], Xs[ns_perclass:, 1], |
219 | | - marker='o', |
220 | | - edgecolor='black', |
221 | | - color='red', |
222 | | - ) |
223 | | -ax[0].set_title('Model: Source\nAcc on source data: {:.2f}\nAcc on target data: {:.2f}'.format(score_src_src, score_src_trgt), |
224 | | - fontsize=11) |
225 | | -ax[0].legend() |
| 197 | +# # Data on which to plot source |
| 198 | +# x_min, x_max = Xs[:, 0].min() - 1, Xs[:, 0].max() + 1 |
| 199 | +# y_min, y_max = Xs[:, 1].min() - 1, Xs[:, 1].max() + 1 |
| 200 | +# xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), |
| 201 | + # np.arange(y_min, y_max, plot_step)) |
| 202 | +# # Plot source model |
| 203 | +# Z = clf_source.predict(np.c_[xx.ravel(), yy.ravel()]) |
| 204 | +# Z = Z.reshape(xx.shape) |
| 205 | +# fig, ax = plt.subplots(nrows=1, ncols=len(methods) + 1, figsize=(30, 3)) |
| 206 | +# ax[0].contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8) |
| 207 | +# ax[0].scatter(Xs[0, 0], Xs[0, 1], |
| 208 | + # marker='o', |
| 209 | + # edgecolor='black', |
| 210 | + # color='white', |
| 211 | + # label='source data', |
| 212 | + # ) |
| 213 | +# ax[0].scatter(Xs[:ns_perclass, 0], Xs[:ns_perclass, 1], |
| 214 | + # marker='o', |
| 215 | + # edgecolor='black', |
| 216 | + # color='blue', |
| 217 | + # ) |
| 218 | +# ax[0].scatter(Xs[ns_perclass:, 0], Xs[ns_perclass:, 1], |
| 219 | + # marker='o', |
| 220 | + # edgecolor='black', |
| 221 | + # color='red', |
| 222 | + # ) |
| 223 | +# ax[0].set_title('Model: Source\nAcc on source data: {:.2f}\nAcc on target data: {:.2f}'.format(score_src_src, score_src_trgt), |
| 224 | + # fontsize=11) |
| 225 | +# ax[0].legend() |
226 | 226 |
|
227 | | -# Data on which to plot target |
228 | | -x_min, x_max = Xt[:, 0].min() - 1, Xt[:, 0].max() + 1 |
229 | | -y_min, y_max = Xt[:, 1].min() - 1, Xt[:, 1].max() + 1 |
230 | | -xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), |
231 | | - np.arange(y_min, y_max, plot_step)) |
232 | | -# Plot transfer models |
233 | | -for i, (method, label, score) in enumerate(zip(methods, labels, scores)): |
234 | | - clf_transfer = clfs[i] |
235 | | - Z_transfer = clf_transfer.predict(np.c_[xx.ravel(), yy.ravel()]) |
236 | | - Z_transfer = Z_transfer.reshape(xx.shape) |
237 | | - ax[i + 1].contourf(xx, yy, Z_transfer, cmap=plt.cm.coolwarm, alpha=0.8) |
238 | | - ax[i + 1].scatter(Xt[0, 0], Xt[0, 1], |
239 | | - marker='o', |
240 | | - edgecolor='black', |
241 | | - color='white', |
242 | | - label='target data', |
243 | | - ) |
244 | | - ax[i + 1].scatter(Xt[:nt_0, 0], Xt[:nt_0, 1], |
245 | | - marker='o', |
246 | | - edgecolor='black', |
247 | | - color='blue', |
248 | | - ) |
249 | | - ax[i + 1].scatter(Xt[nt_0:, 0], Xt[nt_0:, 1], |
250 | | - marker='o', |
251 | | - edgecolor='black', |
252 | | - color='red', |
253 | | - ) |
254 | | - ax[i + 1].set_title('Model: {}\nAcc on target data: {:.2f}'.format(label, score), |
255 | | - fontsize=11) |
256 | | - ax[i + 1].legend() |
| 227 | +# # Data on which to plot target |
| 228 | +# x_min, x_max = Xt[:, 0].min() - 1, Xt[:, 0].max() + 1 |
| 229 | +# y_min, y_max = Xt[:, 1].min() - 1, Xt[:, 1].max() + 1 |
| 230 | +# xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), |
| 231 | + # np.arange(y_min, y_max, plot_step)) |
| 232 | +# # Plot transfer models |
| 233 | +# for i, (method, label, score) in enumerate(zip(methods, labels, scores)): |
| 234 | + # clf_transfer = clfs[i] |
| 235 | + # Z_transfer = clf_transfer.predict(np.c_[xx.ravel(), yy.ravel()]) |
| 236 | + # Z_transfer = Z_transfer.reshape(xx.shape) |
| 237 | + # ax[i + 1].contourf(xx, yy, Z_transfer, cmap=plt.cm.coolwarm, alpha=0.8) |
| 238 | + # ax[i + 1].scatter(Xt[0, 0], Xt[0, 1], |
| 239 | + # marker='o', |
| 240 | + # edgecolor='black', |
| 241 | + # color='white', |
| 242 | + # label='target data', |
| 243 | + # ) |
| 244 | + # ax[i + 1].scatter(Xt[:nt_0, 0], Xt[:nt_0, 1], |
| 245 | + # marker='o', |
| 246 | + # edgecolor='black', |
| 247 | + # color='blue', |
| 248 | + # ) |
| 249 | + # ax[i + 1].scatter(Xt[nt_0:, 0], Xt[nt_0:, 1], |
| 250 | + # marker='o', |
| 251 | + # edgecolor='black', |
| 252 | + # color='red', |
| 253 | + # ) |
| 254 | + # ax[i + 1].set_title('Model: {}\nAcc on target data: {:.2f}'.format(label, score), |
| 255 | + # fontsize=11) |
| 256 | + # ax[i + 1].legend() |
257 | 257 |
|
258 | | -# fig.savefig('../images/ser_strut.png') |
259 | | -plt.show() |
| 258 | +# # fig.savefig('../images/ser_strut.png') |
| 259 | +# plt.show() |
260 | 260 |
|
0 commit comments