RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-307655

leonardik's questions

Martin Hope
leonardik
Asked: 2024-09-11 18:14:36 +0000 UTC

Keras - 在 Excel 中记录预测

  • 5

假设有一个 Excel 表格,其中 A 列是输入,B 列是神经网络的输出。我需要经过训练的网络在源 Excel 文件的 C 列中写入它根据 A 列中的值计算出的预测。但是 Python 没有进行预测,而是给出了错误。我做错了什么?或者应该将预测写入新文件?

import pandas as pd
import numpy as np
import tensorflow
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense


df=pd.read_excel('/content/test.xlsx')
input_data=np.asarray(df.iloc[:,0].values.tolist())

x=input_data.reshape(29,1)
y=np.asarray(df.iloc[:,1].values.tolist())

model = Sequential()

model.add(Dense(20, activation='relu'))
model.compile(loss='mse', optimizer=keras.optimizers.Adam(0.1), metrics=['mae'])

 # Fit the model
model.fit(x, y, epochs=5, batch_size=1)

df['C']=model.predict(x)
keras
  • 1 个回答
  • 15 Views
Martin Hope
leonardik
Asked: 2024-07-11 23:34:24 +0000 UTC

Keras - 如何解码网络结果?

  • 5

我创建了一个应该学习识别偶数和奇数的代码,给出“是”或“否”的答案。该脚本在训练期间不会显示任何错误,它的准确度约为 55%,但当我尝试输入第三方数字(在我的例子中为 33)时,它会生成某种代码。如何将其转换为“是”或“否”?

import numpy as np
from keras.models import Sequential
from keras.layers import LSTM, Dense
from keras.utils import to_categorical

# Data preparation
X = np.array([2,3,4,5,6,7,8,9,10])
y = np.array(['yes','no','yes','no','yes','no','yes','no','yes'])
# encode the labels
classes = ['yes', 'no']
y = to_categorical([classes.index(label) for label in y])

X = array(X).reshape(9, 1, 1)
# Define the LSTM model
model = Sequential()
model.add(LSTM(128, input_shape=(1,1)))
model.add(Dense(len(classes), activation='sigmoid'))

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

# Fit the model
model.fit(X, y, epochs=10, batch_size=1)

# Make predictions
X = np.array([33])
test_input = X.reshape((1, 1, 1))
test_output = model.predict(test_input, verbose=0)
print (test_output)
python
  • 1 个回答
  • 8 Views
Martin Hope
leonardik
Asked: 2022-07-15 02:29:21 +0000 UTC

Python - 在给定步骤的列表内求和

  • 1

大家好。我对以下情况感到困惑。我有一个包含 60 个值的 mList,我需要以 20 为增量求和。下面的脚本给出了错误的值

import numpy as np
res=[]
for i in range(0,len(mList),20):
    r=np.sum(mList[i:i+20])
    res.append(r)
print(res)

但是,如果您在此表单中添加“按索引”,则会获得正确的答案

np.sum(mList[0:20])
np.sum(mList[21:40])
np.sum(mList[41:60])

除其他外,我对测试列表中的结果结果是正确的事实感到困惑。

import numpy as np
mList=[1,1,1,2,2,2,3,3,3]

res=[]
for i in range(0,len(mList),3):
    r=np.sum(mList[i:i+3])
    res.append(r)
print(res)

请告诉我如何才能得到正确的答案?实际列表将包含数千个值...

python
  • 4 个回答
  • 77 Views
Martin Hope
leonardik
Asked: 2022-07-13 22:42:05 +0000 UTC

Python-Pandas - 如何拆分表?

  • 0

大家好!有一个表格需要分成 3 行的块,然后通过 iloc 使用公式,将相邻单元格相加,然后将结果数量相加。当前脚本生成一个 list [2, 4, 6, 8, 10, 12],但结果应该[12,30]是 ,即 2 + 4 + 6 和 8 + 10 + 12 相加。

我没有找到 Pandas 的拆分功能...

import pandas as pd
import numpy as np
cont={'Part_1':[1,2,3,4,5,6],
      'Part_2':[1,2,3,4,5,6]
      }
index_list=['r1','r2','r3','r4','r5','r6']
df = pd.DataFrame(cont,index_list)

fig=[]
for i in range(0,len(df)):
    fig_p=df.iloc[i,0]+df.iloc[i,1]
    fig.append(fig_p)

print (fig)
print(np.sum(fig))
python
  • 1 个回答
  • 51 Views
Martin Hope
leonardik
Asked: 2022-06-28 20:26:54 +0000 UTC

以给定的步骤滚动

  • 1

大家好!有一个脚本使用滚动来查找列中的最大值。当前窗口步长 = 1,即(1,3,1)下一个滑动序列(3,1,5)等。

如何设置 step = 3,即序列为(1,3,1)and (5,10,5)?

屏幕截图显示了窗口的移动,脚本最终应显示的最大值以红色突出显示。

在此处输入图像描述

找到了解决方案df.rolling(window=3,step=3),但它不起作用......

import pandas as pd
sample = {
    'ID':[1,1,1,9,9,9],
    'Quant' :[1,3,1,5,10,5]
              }
df = pd.DataFrame(sample)

df2=df.rolling(3).agg({'Quant':'max'})
df3=df2.dropna(how='all')
print(df3)
python pandas
  • 2 个回答
  • 76 Views
Martin Hope
leonardik
Asked: 2022-06-25 17:42:35 +0000 UTC

Python - Pandas,时差计算

  • 0

大家好!有一个 df 表,其中包含“小时:分钟”格式的数据,您需要为此计算行之间的差异(以分钟为单位)。当前脚本应返回整数值 65 (01:15 - 00:10),但到目前为止它给出了一个错误,即格式不匹配...

import pandas as pd
from datetime import datetime

df = pd.DataFrame({'Time':['00:10','01:15','02:45','04:00']})

corr1=str(df.iloc[0,:])
corr2=str(df.iloc[1,:])
res1 = datetime.strptime(corr1,'%H:%M')
res2 = datetime.strptime(corr2,'%H:%M')
diff=res2-res1

print(diff)
python pandas
  • 1 个回答
  • 52 Views
Martin Hope
leonardik
Asked: 2022-06-13 18:43:51 +0000 UTC

如何确定至少一个值是否小于 10

  • 0

需要一个脚本来检查列表的值。我不知道如何注册如果任何值\u200b\u200bis小于10,那么控制台中会显示一个OK。

a=[1.2, 2.4, 2.7, 3.0, 3.1, 7.2]
for i in range(len(a)):

    if  a[0]>20 or a[i]>10 :
        print('No')
        break
    elif a[i]<10:
        continue
        print('Ok')
python
  • 4 个回答
  • 10 Views
Martin Hope
leonardik
Asked: 2022-09-04 20:20:13 +0000 UTC

Python - 查找范围内的最大值

  • 1

大家好!有一个列表 a,从中计算累积总数(列表 x)。列表 x 中的下一个是搜索最小值和最大值,必须严格 (!) 到最小值。由于某种原因,当前版本返回整个列表 x (41) 的最大值,但应该是 17

import numpy as np

a=[17,-2,8,17,1,-7,3, -15,19, -13]
x=list(np.cumsum(a))
y=min(x)
z=max(x[:y])


print(f'list {x}')
print(f'minimum {y}')
print(f'maximum {z}')
python
  • 1 个回答
  • 10 Views
Martin Hope
leonardik
Asked: 2022-08-25 15:28:30 +0000 UTC

Python - 如何在没有 zip 的情况下重写列表生成器?

  • 0

大家好。有两个列表,并且有一个比较这些列表的脚本

a=[10,20,30,40,50,60,40,45]
x=[10,50,5,100,15,60]
print([i > j for i, j in zip(a[-len(x):], x)])

我需要以“熟悉的格式”重写它,但生成的代码给出了错误的结果。我该怎么办?

a=[10,20,30,40,50,60,40,45]
x=[10,50,5,100,15,60]

for i in range (a[-len(x)]):
    for j in range(len(x)):
        if i>j:
            print('True')
        else:
            print('False')
python
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5