参考:
1、《Python机器学习:预测分析核心算法》 P258-P266
1 importnumpy2
3 #from sklearn.cross_validation import train_test_split
4 from sklearn.model_selection importtrain_test_split5
6 #这里是可以用来构建GradientBoostingRegressor模型
7 from sklearn importensemble8 from sklearn.metrics importmean_squared_error9 import pylab as plot
1 #从本机读取数据
2 target_file = open('winequality-red.csv','r')3 data =target_file.readlines()4 target_file.close()
1 #整理原始数据,将原始数据分为属性列表(xList),标签列表(labels)
2 #将各个属性的名称存入names列表
3 xList =[]4 labels =[]5 names =[]6 firstLine =True7 for line indata:8 iffirstLine:9 names = line.strip().split(";")10 firstLine =False11 else:12 #split on semi-colon
13 row = line.strip().split(";")14 #put labels in separate array
15 labels.append(float(row[-1]))16 #remove