2-神经网络起源-demo3-共享单车__小批量多隐藏层_答案

本博客详细介绍了使用深度学习预测共享单车骑行需求的项目流程,包括数据预处理、特征工程、模型搭建与训练,以及最终的预测结果展示。通过实际案例,深入理解深度学习在网络架构、超参数调整及模型优化方面的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 解决pd中print中间省略的问题
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)

# 读取数据
data_path = './Bike-Sharing-Dataset/hour.csv'
rides = pd.read_csv(data_path)


def f1():
    print(rides.head())
    print(rides.describe())
    rides.info()


def f2(rides):
    """
    # 一、季节、天气(分类变量)、月份、小时、星期几
    都是分类变量,需要调整为哑变量。
    """
    dummy_fields = ['season', 'weathersit', 'mnth', 'hr', 'weekday']
    for each in dummy_fields:
        dummies = pd.get_dummies(rides[each], prefix=each, drop_first=False)
        rides = pd.concat([rides, dummies], axis=1)
    """
    二、除了将 上面的原变量,还有以下变量需要删除,思考下why?
    1、instant 记录索引号;
    2、dteday  具体某天的日期号;
    3、atemp  体感温度,和temp重复,故删除;
    4、workingday 是否工作日,和weekday重复了,故删除;
    """
    fields_to_drop = ['instant', 'dteday', 'season', 'weathersit',
                      'weekday', 'atemp', 'mnth', 'workingday', 'hr']
    data = rides.drop(fields_to_drop, axis=1)
    print(data.head())

    # rides[:24 * 10].plot(x='dteday', y='cnt')
    # plt.show()
    return data


def f3(data):
    """
    连续变量的数据标准化
    注意:cnt 就是target
    """
    quant_features = ['casual', 'registered', 'cnt', 'temp', 'hum', 'windspeed']
    # 将换算因子进行保存,以便在预测的时候还原数据。
    scaled_features = {}
    for each in quant_features:
        mean, std = data[each].mean(), data[each].std()
        scaled_features[each] = [mean, std]
        data.loc[:, each] = (data[each] - mean) / std
    return data, scaled_features


def f4(data):
    """
    拆分数据集,拆分 特征 和 target
    """
    # 保存最后21天 作为测试数据集
    test_data = data[-21 * 24:]

    # 移除最后21天数据,作为训练数据集
    data = data[:-21 * 24]

    # 将特征值 和 target进行拆分
    target_fields = ['cnt', 'casual', 'registered']
    features, targets = data.drop(target_fields, axis=1), data[target_fields]
    test_features, test_targets = test_data.drop(target_fields, axis=1), test_data[target_fields]
    return features, targets, test_features, test_targets


def f5(features , targets):
    """
    使用训练数据集的后60天数据,作为验证数据集;在模型训练过程中进行验证模型的效果。
    """
    train_features, train_targets = features[:-60 * 24], targets[:-60 * 24]
    val_features, val_targets = features[-60 * 24:], targets[-60 * 24:]
    return train_features, train_targets, val_features, val_targets


class NeuralNetworkMultiHidden(object):
    def __init__(self, input_nodes, hidden_nodes1, hidden_nodes2, output_nodes, learning_rate,
                 keep_prob=0.75, batch_size=128):
        """
        :param input_nodes:   输入的节点数量 (特征数量)
        :param hidden_nodes:  隐藏层节点数量
        :param output_nodes:  输出层节点数量
        :param learning_rate:
        """
        # Set number of nodes in input, hidden and output layers.
        self.input_nodes = input_nodes
        self.hidden_nodes1 = hidden_nodes1
        self.hidden_nodes2 = hidden_nodes2
        self.output_nodes = output_nodes
        self.batch_size = batch_size
        self.lr = learning_rate
        self.keep_prob = keep_prob

        # 初始化权重
        self.weights_input_to_h1 = np.random.normal(
            0.0, 1/self.input_nodes ** -0.5, size=(self.input_nodes, self.hidden_nodes1))
        self.weights_h1_to_h2 = np.random.normal(
            0.0, 1/self.hidden_nodes1 ** -0.5, size=(self.hidden_nodes1, self.hidden_nodes2))
        self.weights_h2_to_output = np.random.normal(
            0.0, 1/self.hidden_nodes2 ** -0.5, size=(self.hidden_nodes2, self.output_nodes))
        self.lr = learning_rate

        # TODO: 设置 self.activation_function 来部署 sigmoid 函数
        self.activation_function = lambda x: 1/(1+np.exp(-x))

    def get_batches(self, features, targets):
        assert len(features) == len(targets)
        for i in range(0, len(features), self.batch_size):
            yield features[i: i+self.batch_size], targets[i: i+self.batch_size]

    def drop_out(self, x):
        """
        实现dropout函数
        :param x:
        :return:
        """
        keep_prob = (np.random.rand(*x.shape) < self.keep_prob) / self.keep_prob
        return keep_prob

    def train_batch(self, features, targets):
        """
        MBGD的实现
        :param features:
        :param targets:
        :return:
        """
        for batch_x, batch_y in self.get_batches(features, targets):
            # 1、正向传播
            # TODO: 隐藏层
            h1_inputs = np.matmul(batch_x, self.weights_input_to_h1)
            h1_outputs = self.activation_function(h1_inputs)
            h1_outputs = h1_outputs * self.drop_out(h1_outputs)

            h2_inputs = np.matmul(h1_outputs, self.weights_h1_to_h2)
            h2_outputs = self.activation_function(h2_inputs)
            h2_outputs = h2_outputs * self.drop_out(h2_outputs)

            # TODO: 输出层
            final_inputs = np.matmul(h2_outputs, self.weights_h2_to_output)
            y_hat = final_inputs

            # 二、反向传播
            # 1\Output error
            error = y_hat - batch_y.reshape([-1, 1])  # [batch, 1]

            # 2: 计算隐藏层对误差error的贡献
            output_error_term = error * 1

            # 3、 计算 h2 to output权重的梯度
            delta_h2_to_output = np.matmul(np.transpose(h2_outputs), output_error_term) / self.batch_size

            # 4、h2 隐藏层误差项
            h2_error_term = np.matmul(output_error_term, self.weights_h2_to_output.transpose()) * h2_outputs * (1-h2_outputs)
            # 5\ h1 to h2权重的梯度值
            delta_h1_to_h2 = np.matmul(np.transpose(h1_outputs), h2_error_term) / self.batch_size

            # 6、求 h1隐藏层误差项
            h1_error_term = np.matmul(h2_error_term, self.weights_h1_to_h2.transpose()) * h1_outputs*(1-h1_outputs)

            # 7、求input to h1权重的梯度
            delta_input_to_h1 = np.matmul(np.transpose(batch_x), h1_error_term) / self.batch_size

            # 8执行梯度下降
            self.weights_input_to_h1 -= delta_input_to_h1 * self.lr
            self.weights_h1_to_h2 -= delta_h1_to_h2 * self.lr
            self.weights_h2_to_output -= delta_h2_to_output * self.lr

    def run(self, features):
        '''
        预测函数。
        使用输入特征,执行1次正向传播,得到预测值
        features: 1D array of feature values
        '''
        # 1、正向传播
        # TODO: 隐藏层
        h1_inputs = np.matmul(features.values, self.weights_input_to_h1)
        h1_outputs = self.activation_function(h1_inputs)

        h2_inputs = np.matmul(h1_outputs, self.weights_h1_to_h2)
        h2_outputs = self.activation_function(h2_inputs)

        # TODO: 输出层
        final_inputs = np.matmul(h2_outputs, self.weights_h2_to_output)
        y_hat = final_inputs

        return y_hat


def MSE(y, Y):
    return np.mean((y-Y)**2)

# 显示训练过程中的训练 和 验证损失
def show(losses):
    plt.plot(losses['train'], label='Training loss')
    plt.plot(losses['validation'], label='Validation loss')
    plt.legend()
    _ = plt.ylim()
    plt.show()


def test(network,scaled_features, test_features, test_targets, rides):
    fig, ax = plt.subplots(figsize=(8, 4))
    mean, std = scaled_features['cnt']
    predictions = network.run(test_features).T * std + mean
    ax.plot(predictions[0], label='Prediction')
    ax.plot((test_targets['cnt'] * std + mean).values, label='Data')
    ax.set_xlim(right=len(predictions))
    ax.legend()

    dates = pd.to_datetime(rides.iloc[test_features.index]['dteday'])
    dates = dates.apply(lambda d: d.strftime('%b %d'))
    ax.set_xticks(np.arange(len(dates))[12::24])
    _ = ax.set_xticklabels(dates[12::24], rotation=45)
    plt.show()


if __name__ == '__main__':
    # f1()
    data = f2(rides)
    data, scaled_features = f3(data)
    features, targets, test_features, test_targets = f4(data)
    train_features, train_targets, val_features, val_targets = f5(features, targets)
    # todo 设置超参数 ###
    epochs = 3000        # 迭代次数
    learning_rate = 0.1  # 学习率
    hidden_nodes1 = 8   # 隐藏层节点数量,决定你模型的复杂度。
    hidden_nodes2 = 7
    output_nodes = 1   # 输出层的节点数量。
    batch_size = 256
    keep_prob = 0.8
    input_nodes = train_features.shape[1]

    network = NeuralNetworkMultiHidden(
        input_nodes, hidden_nodes1, hidden_nodes2, output_nodes,
        learning_rate, keep_prob=keep_prob, batch_size=batch_size)

    losses = {'train': [], 'validation': []}
    for epoch in range(epochs):
        network.train_batch(train_features.values, train_targets['cnt'].values)

        # 打印出训练过程
        train_loss = MSE(network.run(train_features).T, train_targets['cnt'].values)
        val_loss = MSE(network.run(val_features).T, val_targets['cnt'].values)
        if epoch % 20 == 0:
            print('训练迭代次数:{},训练损失:{} ,验证损失:'
                  '{}'.format(epoch, train_loss, val_loss))

        losses['train'].append(train_loss)
        losses['validation'].append(val_loss)

    show(losses)
    test(network, scaled_features, test_features, test_targets, rides)

D:\Anaconda\python.exe "D:\PyCharm\PyCharm 2018.2.2\helpers\pydev\pydevconsole.py" 54140 54141
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['D:\\AI20\\HJZ', 'D:/AI20/HJZ'])
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 6.4.0
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
runfile('D:/AI20/HJZ/04-深度学习/1-深度学习入门/深度学习项目/AI20_单车__小批量多隐藏层_答案.py', wdir='D:/AI20/HJZ/04-深度学习/1-深度学习入门/深度学习项目')
   yr  holiday  temp   hum  windspeed  casual  registered  cnt  season_1  season_2  season_3  season_4  weathersit_1  weathersit_2  weathersit_3  weathersit_4  mnth_1  mnth_2  mnth_3  mnth_4  mnth_5  mnth_6  mnth_7  mnth_8  mnth_9  mnth_10  mnth_11  mnth_12  hr_0  hr_1  hr_2  hr_3  hr_4  hr_5  hr_6  hr_7  hr_8  hr_9  hr_10  hr_11  hr_12  hr_13  hr_14  hr_15  hr_16  hr_17  hr_18  hr_19  hr_20  hr_21  hr_22  hr_23  weekday_0  weekday_1  weekday_2  weekday_3  weekday_4  weekday_5  weekday_6
0   0        0  0.24  0.81        0.0       3          13   16         1         0         0         0             1             0             0             0       1       0       0       0       0       0       0       0       0        0        0        0     1     0     0     0     0     0     0     0     0     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0          0          0          0          0          0          0          1
1   0        0  0.22  0.80        0.0       8          32   40         1         0         0         0             1             0             0             0       1       0       0       0       0       0       0       0       0        0        0        0     0     1     0     0     0     0     0     0     0     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0          0          0          0          0          0          0          1
2   0        0  0.22  0.80        0.0       5          27   32         1         0         0         0             1             0             0             0       1       0       0       0       0       0       0       0       0        0        0        0     0     0     1     0     0     0     0     0     0     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0          0          0          0          0          0          0          1
3   0        0  0.24  0.75        0.0       3          10   13         1         0         0         0             1             0             0             0       1       0       0       0       0       0       0       0       0        0        0        0     0     0     0     1     0     0     0     0     0     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0          0          0          0          0          0          0          1
4   0        0  0.24  0.75        0.0       0           1    1         1         0         0         0             1             0             0             0       1       0       0       0       0       0       0       0       0        0        0        0     0     0     0     0     1     0     0     0     0     0      0      0      0      0      0      0      0      0      0      0      0      0      0      0          0          0          0          0          0          0          1
训练迭代次数:0,训练损失:1.4049598343209766 ,验证损失:1.4134166663142764
训练迭代次数:20,训练损失:1.191033061166735 ,验证损失:1.2931418136345434
训练迭代次数:40,训练损失:1.1984009623831025 ,验证损失:1.2920684294502167
训练迭代次数:60,训练损失:1.2128614744725161 ,验证损失:1.2890902536743876
训练迭代次数:80,训练损失:1.1920010882383159 ,验证损失:1.2781289512063165
训练迭代次数:100,训练损失:1.2006819864036042 ,验证损失:1.2669214154589938
训练迭代次数:120,训练损失:1.201754896935542 ,验证损失:1.2543690660827465
训练迭代次数:140,训练损失:1.191243393043961 ,验证损失:1.2386061002917468
训练迭代次数:160,训练损失:1.1663420353206133 ,验证损失:1.2133403530787898
训练迭代次数:180,训练损失:1.1854967589152083 ,验证损失:1.2038260345349165
训练迭代次数:200,训练损失:1.1795672537011166 ,验证损失:1.1823249575128574
训练迭代次数:220,训练损失:1.1682780833044055 ,验证损失:1.1699543809357753
训练迭代次数:240,训练损失:1.1636495190832759 ,验证损失:1.153493583812518
训练迭代次数:260,训练损失:1.1683817941847439 ,验证损失:1.1530397929143232
训练迭代次数:280,训练损失:1.1704024692290609 ,验证损失:1.1463094551941384
训练迭代次数:300,训练损失:1.167836729294609 ,验证损失:1.1380138358655458
训练迭代次数:320,训练损失:1.152206893299751 ,验证损失:1.1268447929175738
训练迭代次数:340,训练损失:1.1398153088544771 ,验证损失:1.1141464353215857
训练迭代次数:360,训练损失:1.1399555109674233 ,验证损失:1.1173589548792964
训练迭代次数:380,训练损失:1.1339803999528923 ,验证损失:1.1058483596575561
训练迭代次数:400,训练损失:1.127499637809135 ,验证损失:1.0943699867988634
训练迭代次数:420,训练损失:1.130508289149735 ,验证损失:1.094848660480854
训练迭代次数:440,训练损失:1.1226987785233933 ,验证损失:1.0868869679815947
训练迭代次数:460,训练损失:1.1124556323539798 ,验证损失:1.0880393700260946
训练迭代次数:480,训练损失:1.0947664417341665 ,验证损失:1.0822969246723875
训练迭代次数:500,训练损失:1.102019574807323 ,验证损失:1.0785993278226347
训练迭代次数:520,训练损失:1.0756653061870864 ,验证损失:1.0739512911587645
训练迭代次数:540,训练损失:1.0848392163051497 ,验证损失:1.071863377072026
训练迭代次数:560,训练损失:1.0726029326883686 ,验证损失:1.0662775420905442
训练迭代次数:580,训练损失:1.0573534852202195 ,验证损失:1.0714235515825197
训练迭代次数:600,训练损失:1.0383465103374563 ,验证损失:1.061587838801731
训练迭代次数:620,训练损失:1.025923333984107 ,验证损失:1.0653288968309416
训练迭代次数:640,训练损失:1.0369456811847073 ,验证损失:1.0713373240243294
训练迭代次数:660,训练损失:1.0364001667139042 ,验证损失:1.0640935566218894
训练迭代次数:680,训练损失:1.0400004910395533 ,验证损失:1.065681599324164
训练迭代次数:700,训练损失:1.050995284262165 ,验证损失:1.0647670884860212
训练迭代次数:720,训练损失:1.018940240035332 ,验证损失:1.059287874059955
训练迭代次数:740,训练损失:1.0363819632576774 ,验证损失:1.066276341690848
训练迭代次数:760,训练损失:1.028426813397832 ,验证损失:1.0623961167773956
训练迭代次数:780,训练损失:1.0189745034921762 ,验证损失:1.0624564548702664
训练迭代次数:800,训练损失:1.0535661337931692 ,验证损失:1.0668193865406113
训练迭代次数:820,训练损失:1.0266509285859535 ,验证损失:1.068206513591057
训练迭代次数:840,训练损失:1.0331621655804455 ,验证损失:1.0726722273363603
训练迭代次数:860,训练损失:1.0251174045688107 ,验证损失:1.0654138978355179
训练迭代次数:880,训练损失:1.0304148623045695 ,验证损失:1.0656984457855712
训练迭代次数:900,训练损失:1.024423315282759 ,验证损失:1.0700745167114185
训练迭代次数:920,训练损失:1.032328343800837 ,验证损失:1.0624130680251542
训练迭代次数:940,训练损失:1.0283687484682102 ,验证损失:1.0773623767903766
训练迭代次数:960,训练损失:1.0134267116061493 ,验证损失:1.074257335227338
训练迭代次数:980,训练损失:1.0110943715100067 ,验证损失:1.0785358764065802
训练迭代次数:1000,训练损失:1.0137399554429194 ,验证损失:1.0891244094584875
训练迭代次数:1020,训练损失:0.9976091453098368 ,验证损失:1.1036601448902938
训练迭代次数:1040,训练损失:1.0025455852046654 ,验证损失:1.1078044097173811
训练迭代次数:1060,训练损失:0.9971201783057869 ,验证损失:1.1097782177478874
训练迭代次数:1080,训练损失:1.0077135024045787 ,验证损失:1.1171342596149176
训练迭代次数:1100,训练损失:0.989435521338311 ,验证损失:1.1163947695415941
训练迭代次数:1120,训练损失:1.0046778115903863 ,验证损失:1.116652012791937
训练迭代次数:1140,训练损失:0.9890504798273926 ,验证损失:1.116016089697368
训练迭代次数:1160,训练损失:0.9843516216949189 ,验证损失:1.1052671666140421
训练迭代次数:1180,训练损失:1.0064311979803187 ,验证损失:1.1049940415771407
训练迭代次数:1200,训练损失:0.998841749230865 ,验证损失:1.0985993017086981
训练迭代次数:1220,训练损失:0.9862143891130666 ,验证损失:1.0903739899913933
训练迭代次数:1240,训练损失:0.9810610274347947 ,验证损失:1.0885378134649732
训练迭代次数:1260,训练损失:0.9792300562416918 ,验证损失:1.077161582076293
训练迭代次数:1280,训练损失:0.9760627779270655 ,验证损失:1.0730553186056613
训练迭代次数:1300,训练损失:0.967982277710496 ,验证损失:1.0630035815717724
训练迭代次数:1320,训练损失:0.9717968522519344 ,验证损失:1.053997539353016
训练迭代次数:1340,训练损失:0.9743654642216101 ,验证损失:1.0558319503303484
训练迭代次数:1360,训练损失:0.9680533949739022 ,验证损失:1.0506383794413203
训练迭代次数:1380,训练损失:0.9709026169373867 ,验证损失:1.0532973030862018
训练迭代次数:1400,训练损失:0.974128474316653 ,验证损失:1.0498922921766818
训练迭代次数:1420,训练损失:0.9785149046759605 ,验证损失:1.0408913252615668
训练迭代次数:1440,训练损失:0.9537413724379682 ,验证损失:1.0381164051752785
训练迭代次数:1460,训练损失:0.965637541159986 ,验证损失:1.035939389690247
训练迭代次数:1480,训练损失:0.9795617178366891 ,验证损失:1.0330948779622118
训练迭代次数:1500,训练损失:0.9830199380134964 ,验证损失:1.023296422546772
训练迭代次数:1520,训练损失:0.9718277653587923 ,验证损失:1.02374833235857
训练迭代次数:1540,训练损失:0.9871744709311929 ,验证损失:1.0181642903151176
训练迭代次数:1560,训练损失:0.9645553513132961 ,验证损失:1.014631074593417
训练迭代次数:1580,训练损失:0.95745665627693 ,验证损失:1.011575426466816
训练迭代次数:1600,训练损失:0.9891756647749831 ,验证损失:1.0059939313593158
训练迭代次数:1620,训练损失:0.9736988068828757 ,验证损失:1.0091536385132531
训练迭代次数:1640,训练损失:0.9960204223543437 ,验证损失:1.0033607875054935
训练迭代次数:1660,训练损失:0.9854556298410954 ,验证损失:1.0002568588738163
训练迭代次数:1680,训练损失:0.9830104575963702 ,验证损失:1.0005752641230383
训练迭代次数:1700,训练损失:0.9937353633299877 ,验证损失:0.9981942073966672
训练迭代次数:1720,训练损失:0.9930644015954275 ,验证损失:0.994249323972036
训练迭代次数:1740,训练损失:0.9921303783625928 ,验证损失:0.9930527726071848
训练迭代次数:1760,训练损失:1.0012668782395846 ,验证损失:0.9936678586296049
训练迭代次数:1780,训练损失:1.0046846570351382 ,验证损失:0.9904557116907274
训练迭代次数:1800,训练损失:0.9753986592440668 ,验证损失:0.9858319854643595
训练迭代次数:1820,训练损失:0.9862383235682017 ,验证损失:0.9807620309667786
训练迭代次数:1840,训练损失:0.997360058261536 ,验证损失:0.9883861735630757
训练迭代次数:1860,训练损失:0.993343092045557 ,验证损失:0.9859186058806008
训练迭代次数:1880,训练损失:0.9996648339110443 ,验证损失:0.9836449063128594
训练迭代次数:1900,训练损失:0.9890779499154683 ,验证损失:0.988435019455184
训练迭代次数:1920,训练损失:0.9936278333526469 ,验证损失:0.9842544956102532
训练迭代次数:1940,训练损失:0.983567206487514 ,验证损失:0.9860559344032238
训练迭代次数:1960,训练损失:0.9886528359516243 ,验证损失:0.9860672916553115
训练迭代次数:1980,训练损失:1.0003637487457928 ,验证损失:0.987138283627506
训练迭代次数:2000,训练损失:1.0123710735183136 ,验证损失:0.9902226985469503
训练迭代次数:2020,训练损失:0.9904608835359283 ,验证损失:0.9854193298272445
训练迭代次数:2040,训练损失:1.0054704041102138 ,验证损失:0.9874762958896658
训练迭代次数:2060,训练损失:1.027581260124156 ,验证损失:0.991672992135386
训练迭代次数:2080,训练损失:0.989565406914043 ,验证损失:0.984916443161018
训练迭代次数:2100,训练损失:1.0084468607171728 ,验证损失:0.9886431169322287
训练迭代次数:2120,训练损失:0.9942951112223293 ,验证损失:0.9838803991380857
训练迭代次数:2140,训练损失:1.005621205659498 ,验证损失:0.9826214487037916
训练迭代次数:2160,训练损失:0.9970232280450297 ,验证损失:0.9811441899587124
训练迭代次数:2180,训练损失:1.0109055419085602 ,验证损失:0.9817208963062901
训练迭代次数:2200,训练损失:0.9998017953503151 ,验证损失:0.9802820253130723
训练迭代次数:2220,训练损失:0.9983370483596552 ,验证损失:0.979627235574009
训练迭代次数:2240,训练损失:1.0094413724929017 ,验证损失:0.9841338397252996
训练迭代次数:2260,训练损失:1.005974330859626 ,验证损失:0.9818251741135302
训练迭代次数:2280,训练损失:1.0142675598363247 ,验证损失:0.9837754496291757
训练迭代次数:2300,训练损失:1.0127720127438498 ,验证损失:0.9828429365857131
训练迭代次数:2320,训练损失:1.0104569904204563 ,验证损失:0.9800861853389657
训练迭代次数:2340,训练损失:1.0093547783740506 ,验证损失:0.977398843006523
训练迭代次数:2360,训练损失:1.0110058263991355 ,验证损失:0.9815249536367491
训练迭代次数:2380,训练损失:1.0157069324371437 ,验证损失:0.9824352086252541
训练迭代次数:2400,训练损失:1.0069441529695864 ,验证损失:0.9802546909219414
训练迭代次数:2420,训练损失:0.998629288979768 ,验证损失:0.9757994016194351
训练迭代次数:2440,训练损失:1.0264442542787664 ,验证损失:0.9789124302218697
训练迭代次数:2460,训练损失:0.9858533087585518 ,验证损失:0.9753708653306028
训练迭代次数:2480,训练损失:1.0149051626536327 ,验证损失:0.9792163908030725
训练迭代次数:2500,训练损失:1.0257094713748163 ,验证损失:0.9790813165266272
训练迭代次数:2520,训练损失:1.0064263925393622 ,验证损失:0.9716495650211158
训练迭代次数:2540,训练损失:1.0074456081753316 ,验证损失:0.9713535169777512
训练迭代次数:2560,训练损失:1.0045156753470388 ,验证损失:0.9722775864599293
训练迭代次数:2580,训练损失:1.0116777234135117 ,验证损失:0.9734898859818268
训练迭代次数:2600,训练损失:1.008474365142438 ,验证损失:0.9676925039978643
训练迭代次数:2620,训练损失:1.0155960298865223 ,验证损失:0.9713532357071608
训练迭代次数:2640,训练损失:1.042803244913576 ,验证损失:0.9750837335994059
训练迭代次数:2660,训练损失:1.027546771694612 ,验证损失:0.9724091714158932
训练迭代次数:2680,训练损失:1.0336935638889095 ,验证损失:0.9719282835539361
训练迭代次数:2700,训练损失:1.0092632145747278 ,验证损失:0.9717977290574962
训练迭代次数:2720,训练损失:1.0271627014773743 ,验证损失:0.9742688881038355
训练迭代次数:2740,训练损失:1.0137922202722167 ,验证损失:0.9750051808328831
训练迭代次数:2760,训练损失:1.0057584026865223 ,验证损失:0.9726964652883073
训练迭代次数:2780,训练损失:1.0033088589710482 ,验证损失:0.9700467223899546
训练迭代次数:2800,训练损失:1.006040099471596 ,验证损失:0.9738564921842755
训练迭代次数:2820,训练损失:1.011735558239328 ,验证损失:0.9783865020181645
训练迭代次数:2840,训练损失:0.9833877463044207 ,验证损失:0.9769258604374474
训练迭代次数:2860,训练损失:1.027951700601824 ,验证损失:0.9849864397762739
训练迭代次数:2880,训练损失:1.0417753524731448 ,验证损失:0.9869484745302265
训练迭代次数:2900,训练损失:1.0116816678915919 ,验证损失:0.9849301034760884
训练迭代次数:2920,训练损失:1.0111170503145037 ,验证损失:0.9858138725738876
训练迭代次数:2940,训练损失:1.0329653851686955 ,验证损失:0.9948427598844941
训练迭代次数:2960,训练损失:1.0149997393003969 ,验证损失:0.9955813486192334
训练迭代次数:2980,训练损失:1.0111855326181511 ,验证损失:0.9933412663413201

如果报错test:
maybe运行得是pythontest
pycharm,默认运行单元是pythontest
而不是python
解决pytest运行问题

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值