神经网络输入层和隐藏层神经元数量从20改为5时,这段代码怎么改df_real = pd.DataFrame(real, index=None, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Species']) df_prediction = pd.DataFrame(prediction, index=None, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Species'])
时间: 2023-11-28 13:04:53 浏览: 37
当神经网络输入层和隐藏层神经元数量从20改为5时,由于特征数量仍然为4,因此输入层神经元数量应该仍然为4,隐藏层神经元数量应该为5。因此,你需要将代码中的列名从5个改为4个,即去掉隐藏层的神经元数量这一列。修改后的代码如下:
```
df_real = pd.DataFrame(real, index=None, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])
df_prediction = pd.DataFrame(prediction, index=None, columns=['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width'])
```
这样修改后,特征列的数量与神经网络的输入层神经元数量相匹配,可以正常运行。
相关问题
df_concat_x = pd.DataFrame() df_concat_y=pd.DataFrame() df_concat_x1=pd.DataFrame() df_concat_y1=pd.DataFrame()如何代码更简洁
你可以使用列表来存储要合并的数据框,然后使用 pandas 的 concat 函数来合并这些数据框,示例代码如下:
df_list = [df_concat_x, df_concat_y, df_concat_x1, df_concat_y1]
df_concat = pd.concat(df_list)
这样就能更简洁地合并多个数据框了。
df_tmp = pd.DataFrame()
根据提供的引用内容,df_tmp = pd.DataFrame()是创建一个空的DataFrame的语句。DataFrame是Pandas库中的一个数据结构,类似于Excel中的表格,可以用来存储和处理二维数据。在创建DataFrame时,可以通过传入数据、字典、列表等不同的数据类型来初始化。而在引用中,代码cols=df['測項'] df.drop("測項",axis=1,inplace=True) tmp_3 = pd.DataFrame(df.values.T,columns=cols)是将原始数据按列重新排列,并创建一个新的DataFrame。而引用中的代码演示了DataFrame中的loc和iloc两种索引方式的不同之处。loc是基于标签的索引,而iloc是基于位置的索引。通过这两种索引方式,可以对DataFrame进行数据的选择、修改和删除等操作。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)