从一组列表中访问特定列表

def fit(x,y, lrate):    cost_ = []    n_iterations_ = []    w_ = np.zeros((x.shape[1], 1))    m = x.shape[0]    n_iterations = 10    i = 0    while i < n_iterations:        y_pred = np.dot(x, w_)        residuals = y_pred - y        gradient_vector = np.dot(x.T, residuals)        w_ -= (lrate / m) * gradient_vector *(-2)        cost = np.sum((residuals ** 2)) / m        cost_.append(cost)        n_iterations_.append(i)        i+=1    return w_, cost_, n_iterations_learning_rates = [1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1]for i in range(len(learning_rates)):    lr = fit(X_train, y_train,learning_rates[i])    print(lr[1])

当我运行上述代码时,得到以下输出

[576.1537376237624, 576.1545609827812, 576.155384359385, 576.1562077535746, 576.1570311653502, 576.1578545947123, 576.1586780416611, 576.1595015061973, 576.1603249883211, 576.1611484880332][576.1537376237624, 576.161971609612, 576.1702073541688, 576.1784448578509, 576.1866841210765, 576.1949251442638, 576.2031679278315, 576.2114124721976, 576.219658777781, 576.2279068450003][576.1537376237624, 576.2361170484683, 576.3186725320611, 576.4014044933067, 576.48431335199, 576.5673995289181, 576.6506634459224, 576.7341055258611, 576.8177261926215, 576.9015258711238][576.1537376237624, 576.9814884918198, 577.8270339789372, 578.6907997611174, 579.5732219342204, 580.4747472702393, 581.3958334798867, 582.3369494816455, 583.2985756774436, 584.281204235115][576.1537376237624, 584.826908404254, 595.4739343028948, 608.5938411910076, 624.8145782295895, 644.9264682232412, 669.9243443735022, 701.0606295042115, 739.9121998096105, 788.4646133533605][576.1537376237624, 702.4516554203875, 1277.1568412503211, 4042.0736136112046, 17595.436653069664, 84433.45249482371, 414672.7920504886, 2047336.072196413, 10120573.694524828, 50043771.857434966]

我想从输出中访问各个列表,我的期望输出是

[576.1537376237624, 576.1545609827812, 576.155384359385, 576.1562077535746, 576.1570311653502, 576.1578545947123, 576.1586780416611, 576.1595015061973, 576.1603249883211, 576.1611484880332]

回答:

learning_rates = [1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1]all_results=[]for i in range(len(learning_rates)):    lr = fit(X_train, y_train,learning_rates[i])    all_results.append(lr[0])

然后:

for i in range(len(all_results)):    print(all_results[i]) # 逐行打印

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注