91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡(jiǎn)介

python機(jī)器學(xué)習(xí)經(jīng)典實(shí)例【美 Prateek Joshi】修正python3.x版

資源截圖

代碼片段和文件信息

import?sys
import?csv
from?sklearn.ensemble?import?RandomForestRegressor
import?numpy?as?np
from?sklearn.utils?import?shuffle
from?sklearn.metrics?import?mean_squared_error?explained_variance_score
import?matplotlib.pyplot?as?plt

def?plot_feature_importances(feature_importancestitlefeature_names):
????#重要性值標(biāo)準(zhǔn)化
????feature_importances=100.0*(feature_importances/max(feature_importances))
????#得分從高到低排序
????index_sorted=np.flipud(np.argsort(feature_importances))
????#讓X坐標(biāo)軸上的標(biāo)簽居中顯示
????pos=np.arange(index_sorted.shape[0])+0.5

????#畫(huà)圖
????plt.figure()
????plt.bar(posfeature_importances[index_sorted]align=‘center‘)
????plt.xticks(posfeature_names[index_sorted])
????plt.ylabel(‘Relative?Importance‘)
????plt.title(title)
????plt.show()


def?load_dataset(filename):
????file_reader=csv.reader(open(filename‘r‘)delimiter=‘‘)
????xy=[][]
????for?row?in?file_reader:
????????x.append(row[2:13])
????????y.append(row[-1])

????#提取特征名稱(chēng)
????feature_names=np.array(x[0])
????#將第一行特征名稱(chēng)移除,僅保留數(shù)值
????return?np.array(x[1:]).astype(np.float32)np.array(y[1:]).astype(np.float32)feature_names


#讀取數(shù)據(jù),打亂順序
xyfeature_names=load_dataset(‘bike_day.csv‘)
xy=shuffle(xyrandom_state=7)

num_training=int(0.9*len(x))

x_trainy_train=x[:num_training]y[:num_training]
x_testy_test=x[num_training:]y[num_training:]

#決策樹(shù)回歸模型進(jìn)行擬合
rf_regressor=RandomForestRegressor(n_estimators=1000max_depth=10min_samples_split=0.001)
rf_regressor.fit(x_trainy_train)


#評(píng)價(jià)隨機(jī)森林回歸器效果展示
y_pred=rf_regressor.predict(x_test)
mse=mean_squared_error(y_testy_pred)
evs=explained_variance_score(y_testy_pred)
print(‘\n###?Random?Forest?regressor?performance?###‘)
print(‘Mean?squared?error?=‘round(mse2))
print(‘Explained?variance?score=‘round(evs2))

#畫(huà)圖
plot_feature_importances(rf_regressor.feature_importances_‘Random?Forest?regressor‘feature_names)


評(píng)論

共有 條評(píng)論

相關(guān)資源