gplearn demo


from gplearn.genetic import SymbolicTransformer
from sklearn.utils import check_random_state
from sklearn.datasets import load_boston
import numpy as np

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    rng = check_random_state(0)
    boston = load_boston()
    perm = rng.permutation(boston.target.size)
    boston.data = boston.data[perm]
    boston.target = boston.target[perm]

    from sklearn.linear_model import Ridge

    est = Ridge()
    est.fit(boston.data[:300, :], boston.target[:300])
    print(est.score(boston.data[300:, :], boston.target[300:]))

    function_set = ['add', 'sub', 'mul', 'div', 'sqrt', 'log',
                    'abs', 'neg', 'inv', 'max', 'min']
    gp = SymbolicTransformer(generations=20, population_size=2000,
                             hall_of_fame=100, n_components=10,
                             function_set=function_set,
                             parsimony_coefficient=0.0005,
                             max_samples=0.9, verbose=1,
                             random_state=0)
    gp.fit(boston.data[:300, :], boston.target[:300])

    gp_features = gp.transform(boston.data)
    new_boston = np.hstack((boston.data, gp_features))

    est = Ridge()
    est.fit(new_boston[:300, :], boston.target[:300])
    print(est.score(new_boston[300:, :], boston.target[300:]))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

https://github.com/trevorstephens/gplearn/blob/master/doc/gp_examples.ipynbhttps://github.com/trevorstephens/gplearn/blob/master/doc/gp_examples.ipynb

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值