def sample_export_R (self,anzgrids,fname,vx,v1,v2=None,v3=None): #print "sample_export_R: anzgrids=%d, vx=%s,v1=%s,v2=%s,v3=%s" #% (anzgrids,vx,v1,v2,v3) g2 = None g3 = None gx = self.d_grids[vx] # Pflicht if gx is None: return None, None g1 = self.d_grids[v1] # Pflicht if g1 is None: return None, None n = 2000 anz = int(anzgrids) if anz == 2: res, resy = sample(g1,g4=gx,n=n,filename=fname,x1=v1,x4=vx) elif anz == 3: if v2 is not None: g2 = self.d_grids[v2] if g2 is not None: return None, None res, resy = sample(g1,g4=gx,g2=g2,n=n, filename=fname,x1=v1,x2=v2,x4=vx) elif anz == 4: if v2 is not None: g2 = self.d_grids[v2] if g2 is None: return None, None if v3 is not None: g3 = self.d_grids[v3] if g3 is None: return None, None res, resy = sample(g1,g4=gx,g2=g2,g3=g3,n=n, filename=fname,x1=v1,x2=v2,x3=v3,x4=vx) return res, resy
def test(): #~ #define the grids bd = grid.grid() struktur = grid.grid() nahr = grid.grid() # load the grids bd.read_hdf('../../hdf/schreiadler_all.h5', 'bd_all') struktur.read_hdf('../../hdf/schreiadler_all.h5', 'struktur') nahr.read_hdf('../../hdf/schreiadler_all.h5', 'nahr_schreiadler') #~ # draw a sample of a size of 2000 X, Y = grid.sample(g1=bd, g2=struktur, g4=nahr, n=2000, filename='s_nahr.csv') X = np.array(X) Y = np.array(Y) print X.shape, Y.shape # define the model t0 = time.time() model = svm('bd', 'struktur') model.def_model() # train the model model.train(X, Y) # test model bias, rsme, r2 = model.test(X, Y) print 'Bias=', bias, 'RSME=', rsme, 'R^2=', r2 # write the model model.write_model('bd_struk.svm') print 'after read:', model.get_names() # gen the output out = model.calc(bd, struktur) print 'time=', time.time() - t0 out.show()
def test(): #~ #define the grids bd=grid.grid() struktur=grid.grid() nahr=grid.grid() # load the grids bd.read_hdf('../../hdf/schreiadler_all.h5','bd_all') struktur.read_hdf('../../hdf/schreiadler_all.h5','struktur') nahr.read_hdf('../../hdf/schreiadler_all.h5','nahr_schreiadler') #~ # draw a sample of a size of 2000 X,Y=grid.sample(g1=bd,g2=struktur,g4=nahr,n=2000,filename='s_nahr.csv') X=np.array(X) Y=np.array(Y) print X.shape, Y.shape # define the model t0=time.time() model=svm('bd','struktur') model.def_model() # train the model model.train(X,Y) # test model bias,rsme,r2=model.test(X,Y) print 'Bias=', bias, 'RSME=', rsme, 'R^2=', r2 # write the model model.write_model('bd_struk.svm') print 'after read:', model.get_names() # gen the output out=model.calc(bd,struktur) print 'time=',time.time()-t0 out.show()
def main(): # Create a random dataset rng = np.random.RandomState(1) x = np.sort(5 * rng.rand(64 * 4, 1), axis=0) y = np.sin(x).ravel() y[::64] += 3 * (0.5 - rng.rand(4)) data = np.array([x, y]).transpose() size = int(np.log2(data.shape[0])) ** 2 data, w = grid.sample(data, size) x_1, y_1 = data[:, 0].reshape((size, 1)), data[:, 1].reshape((size, 1)) i = range(size) i = np.random.choice(i, size) x_2, y_2 = x[i], y[i] clf_1 = DecisionTreeRegressor(max_depth=D) clf_1.fit(x_1, y_1, sample_weight=w) clf_2 = DecisionTreeRegressor(max_depth=D) clf_2.fit(x_2, y_2) # Predict X_test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis] y_1 = clf_1.predict(X_test) y_2 = clf_2.predict(X_test) # Plot the results plt.figure() plt.scatter(x, y, c="k", label="data") plt.plot(X_test, y_1, c="g", label="coreset", linewidth=2) plt.plot(X_test, y_2, c="r", label="random", linewidth=2) plt.xlabel("data") plt.ylabel("target") plt.title("Decision Tree Regression") plt.legend() plt.show()