光谱波长选择(特征选取)---遗传算法

光谱波长选择(特征选取)—遗传算法

将要解决的问题模拟成一个生物进化的过程,通过复制、交叉、突变等操作产生下一代的解,并逐步淘汰掉适应度函数值低的解,增加适应度函数值高的解。这样进化N代后就很有可能会进化出适应度函数值很高的个体。
数据来源
数据来源https://eigenvector.com/resources/data-sets/

该数据集包含在 3 个不同的 NIR 光谱仪上测量的 80 个玉米样品,波长范围为 1100-2498nm
1.导入数据

data_path = '../../data/corn/m5.csv'  # 数据
label_path = '../../data/corn/label.csv'  # 标签

data = np.loadtxt(open(data_path, 'rb'), dtype=np.float64, delimiter=',', skiprows=0)
X = data[:, :]
label = np.loadtxt(open(label_path, 'rb'), dtype=np.float64, delimiter=',', skiprows=0)  # 用于建模
y = np.array(label[:, 1]).astype(float)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

2.建立回归函数(遗传算法所需的适应度函数)

estimator = SVR(gamma='auto')  # 回归函数
selector = GeneticSelectionCV(estimator,
                              cv=20,
                              verbose=1,
                              scoring="neg_mean_squared_error",
                              max_features=10,
                              n_population=100,
                              crossover_proba=0.5,
                              mutation_proba=0.1,
                              n_generations=200,
                              crossover_independent_proba=0.5,
                              mutation_independent_proba=0.05,
                              tournament_size=3,
                              n_gen_no_change=10,
                              caching=True,
                              n_jobs=-1)

# Train and select the features
selector.fit(X_train, y_train.ravel())

在这里插入图片描述
github仓库地址:https://github.com/STACCCCEY/genetic-algorithm

  • 3
    点赞
  • 112
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值