目录
按照模拟退火算法基本流程的python实现,可以参考模拟退火算法之特征选择的python实现(一)
特此申明:代码是作者辛辛苦苦码的, 转载请注明出处
1. 模拟退火算法之特征选择的python实现(类封装)
import numpy as np
from sklearn.metrics import mean_squared_error
import numpy as np
from sklearn.neural_network import MLPRegressor
import scipy.io as sio
from sklearn.model_selection import train_test_split
class SimulatedAnnealing(object):
"""Feature selection with simulated annealing algorithm.
parameters
----------
initT: int or float, default: 100
The maximum temperature
minT: int or float, default: 1
The minimum temperature
alpha:float, default:0.98
Decay coefficient of temperature
iteration: int, default:50
Balance times at present temperature
features: int
The number of attributes in the original data
init_features_sel: int
The index of selected fatures
estimator: object
A supervised learning estimator with a `fit` method.
Attributes
----------
temp_history: array
record the temperatures
best_cost_history: array
record the MSEs
best_solution_history: array
record the solutions
"""
def __init__(self, features, ini