# stop = None # This random_state is under Linux system. For others system ,the random_state maybe different。 # try with different random_state. stop = lambda ind: ind.fitness.values[0] >= 0.99 sl = SymbolLearning(loop='MultiMutateLoop', pset=pset0, gen=10, pop=3000, hall=1, batch_size=40, re_hall=5, n_jobs=12, mate_prob=0.8, max_value=h_bgp, initial_min=1, initial_max=h_bgp, mutate_prob=0.8, tq=True, dim_type="coef", stop_condition=stop, re_Tree=0, random_state=0, verbose=True, add_coef=True, inter_add=True, cal_dim=False, inner_add=True, personal_map=False) # sl.fit() print(sl.expr)
pset0.add_constants(c, c_dim=c_dim, c_prob=0.05) pset0.add_operations(power_categories=(2, 3, 0.5, 1 / 3, 4, 1 / 4), # categories=("Mul",), categories=("Add", "Mul", "Sub", "Div", "exp", "ln"), self_categories=None) total_height = 3 h_bgp = 2 # This random_state is under Linux system. For others system ,the random_state maybe different,please # try with different random_state. for i in range(1, 10): stop = lambda ind: ind.fitness.values[0] >= 0.95 sl = SymbolLearning(loop="MultiMutateLoop", pset=pset0, gen=20, pop=1000, hall=1, batch_size=40, re_hall=3, n_jobs=12, mate_prob=0.9, max_value=h_bgp, initial_min=2, initial_max=h_bgp, mutate_prob=0.8, tq=False, dim_type="coef", stop_condition=stop, re_Tree=0, store=False, random_state=4, verbose=True, # stats=None, stats={"fitness_dim_max": ["max"], "dim_is_target": ["sum"], "h_bgp": ["mean"]}, add_coef=True, inter_add=True, out_add=True, cal_dim=True, vector_add=True, personal_map=False) tt.t sl.fit() tt.t tt.p score = sl.score(x, y, "r2") print(sl.expr) y_pre = sl.predict(x) break # just for shown # y_pre = si_transformer.scale_y * y_pre # ssc = Dim.inverse_convert(y_dim, target_units=eV)[0]
c = [1, 2, 3] # data = pd.read_csv(r"..data/a.csv") # y = data[:,0] # x = data[:,1:] sl = SymbolLearning( loop="MultiMutateLoop", pop=500, re_hall=3, gen=5, random_state=1, # classification=True, classification=False, # scoring=[metrics.accuracy_score, ], score_pen=[1, ], store=False, # store=True, n_jobs=4, batch_size=20, batch_para=False, # add_coef=False, # out_add =True, # vector_add=True, ) tt.t sl.fit( x, y, c=c, # x_group=[[0, 1], [2, 3]]
# @Time : 2020/12/16 18:53 # @Email : [email protected] # @Software: PyCharm # @License: BSD 3-Clause from sklearn import metrics from sklearn.utils import shuffle if __name__ == "__main__": from sklearn.datasets import fetch_california_housing from bgp.skflow import SymbolLearning data = fetch_california_housing() x = data["data"][:100] y = data["target"][:100] sl = SymbolLearning(loop="MultiMutateLoop", pop=50, gen=2, random_state=1) sl.fit(x, y) score = sl.score(x, y, "r2") print(sl.expr) from sklearn.datasets import load_iris from bgp.skflow import SymbolLearning data = load_iris() x = data["data"][:98, :] x[40:60] = shuffle(x[40:60], random_state=2) y = data["target"][:98] c = None sl = SymbolLearning(loop="MultiMutateLoop", pop=50,
est_gp = SymbolLearning( loop='MultiMutateLoop', pop=1000, gen=20, mutate_prob=0.5, mate_prob=0.8, hall=1, re_hall=1, re_Tree=None, initial_min=None, initial_max=3, max_value=4, scoring=(metrics.mean_absolute_error, ), score_pen=(-1, ), filter_warning=True, cv=1, add_coef=True, inter_add=True, inner_add=True, vector_add=False, out_add=False, flat_add=False, cal_dim=False, dim_type=None, fuzzy=False, n_jobs=8, batch_size=40, random_state=1, stats=None, verbose=True, migrate_prob=0, tq=True, store=True, personal_map=False, stop_condition=None, details=False, classification=False, score_object="y", )
if __name__ == "__main__": from sklearn.datasets import fetch_california_housing from bgp.skflow import SymbolLearning data = fetch_california_housing() x = data["data"][:100] y = data["target"][:100] sl = SymbolLearning(loop="MultiMutateLoop", pop=500, gen=2, random_state=1) sl.fit(x, y, x_group=[[1, 2], [3, 4], [6, 7]]) score = sl.score(x, y, "r2") print(sl.expr)
# classification=True, scoring=[metrics.accuracy_score, ], score_pen=[1, ], # cal_dim=True, n_jobs = 10, store=True, # # ) # # 方式选择3,系数加在公式内层,认定系数可以自动补全量纲 pset0.y_dim = None sl = SymbolLearning( loop="MultiMutateLoop", pop=1000, gen=20, random_state=1, pset=pset0, classification=True, scoring=[ metrics.accuracy_score, ], score_pen=[ 1, ], cal_dim=True, inner_add=True, out_add=False, n_jobs=10, ) # # 方式选择4,系数加在公式内层,不考虑量纲计算, # sl = SymbolLearning(loop="MultiMutateLoop", pop=200, gen=10, random_state=1,pset=pset0, # classification=True, scoring=[metrics.accuracy_score, ], score_pen=[1, ], # cal_dim=False, # inner_add=False, out_add=False, # n_jobs = 2,)
from sklearn.metrics import r2_score, mean_absolute_error dataTi = pd.read_csv("Ti.csv", index_col=0) datanp = dataTi.values x = datanp[:, 1:] y = datanp[:, 0] ind = [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0] index = np.where(np.array(ind) == 1)[0] x = x[:, index] sl = SymbolLearning(loop='MultiMutateLoop', pop=1000, gen=10, random_state=1, n_jobs=1, add_coef=True, initial_max=2, initial_min=1, max_value=2, store=False, ) tt.t sl.fit(x, y) tt.t tt.p print(sl.expr) print(sl.fitness) # y_pre = sl.predict(x) x0 = x[:, 0] x1 = x[:, 1] y_pre2 = x1 / x0 ** 3 s1 = r2_score(y, y_pre2) lr = LinearRegression()
###########第一个########### """数据""" com_data = pd.read_csv(r'FCC.csv') x = com_data.iloc[:, :-1].values y = com_data.iloc[:, -1].values x, y = shuffle(x, y, random_state=0) st = Store("FCC_result_error_no_intercept") st.start() sl = SymbolLearning(loop=r'MultiMutateLoop', cal_dim=False, dim_type=pa_dim, pop=5000, gen=50, add_coef=True, re_hall=2, inter_add=False, random_state=2, n_jobs=16, initial_max=2, max_value=4, store=True, stats={"fitness_dim_max": ("max", )}) sl.fit( x, y, x_dim=[pa_dim, dless, dless, dless, dless, dless, dless], y_dim=pa_dim, power_categories=(2, 3, 0.5, 0.33), categories=("Add", "Mul", "Sub", "Div"), )
x, y = shuffle(x, y, random_state=0) st = Store("reg3_result_error") st.start() sl = SymbolLearning(loop=r'MultiMutateLoop', cal_dim=True, dim_type=None, pop=2000, gen=30, add_coef=True, re_hall=2, scoring=[ error, ], score_pen=[ -1, ], inter_add=False, random_state=3, n_jobs=30, initial_max=3, max_value=6, store=True, stats={ "fitness_dim_min": ("min", ), "dim_is_target": ("sum", ) }) sl.fit( x, y, x_dim=[dless, pa_dim, dless, dless, dless, dless, dless, dless],