- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试执行这段代码,但出现以下错误,随机函数出现错误,我不知道如何解决,请帮助我。
def load_data(sample_split=0.3, usage='Training', to_cat=True, verbose=True,
classes=['Angry','Happy'], filepath='C:/Users/Oussama/Desktop/fer2013.csv'):
df = pd.read_csv(filepath)
# print df.tail()
# print df.Usage.value_counts()
df = df[df.Usage == usage]
frames = []
classes.append('Disgust')
for _class in classes:
class_df = df[df['emotion'] == emotion[_class]]
frames.append(class_df)
data = pd.concat(frames, axis=0)
rows = random.sample(data.index, int(len(data)*sample_split))
data = data.ix[rows]
print ('{} set for {}: {}'.format(usage, classes, data.shape))
data['pixels'] = data.pixels.apply(lambda x: reconstruct(x))
x = np.array([mat for mat in data.pixels]) # (n_samples, img_width, img_height)
X_train = x.reshape(-1, 1, x.shape[1], x.shape[2])
y_train, new_dict = emotion_count(data.emotion, classes, verbose)
print (new_dict)
if to_cat:
y_train = to_categorical(y_train)
return X_train, y_train, new_dict
我明白了:
Traceback (most recent call last):
File "fer2013datagen.py", line 71, in <module>
verbose=True)
File "fer2013datagen.py", line 47, in load_data
rows = random.sample(data, int(len(data)*sample_split))
File"
C:\Users\Oussama\AppData\Local\Programs\Python\Python35\lib\random.py",
line 311, in sample
raise TypeError("Population must be a sequence or set. For dicts, use
list(d).")
TypeError: Population must be a sequence or set. For dicts, use list(d).
最佳答案
你的代码在这里:
rows = random.sample(data.index, int(len(data)*sample_split))
但是,错误信息显示
rows = random.sample(data, int(len(data)*sample_split))
为什么不同?你修改了吗? 数据的类型是什么?是 list 吗?还是听写?
而且,错误消息已经告诉你如何修复它。这意味着 random.sample 的第一个参数必须是一个序列或集合。对于字典,使用 list(Dict)。
例如,
d = {'a':1,'b':2}
random.sample(list(d), 1)
代替
random.sample(d, 1)
关于python - 人口必须是一个序列或集合。对于字典,使用 list(d),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44372231/
我的网页上有两个 DIV 元素。如果 DIV A 的内部 HTML 是通过不受我控制的第三方脚本添加的,我想删除 DIV B 的内部 html。 在 JS 中实现这一目标的最佳方法是什么? 最佳答案
我整个周末都在看这段代码。我知道有数据,我可以通过其他查询提取它,但 GridView 不会显示和填充。有什么建议吗? string sqlSelection =
所以表格在页面上 然后我使用 AJAX 返回数据 $.ajax({ type: 'POST', url: "ticketAjax.php", data: '&m=swapTi
我有一个表格 View Controller ,我正在使用 Storyboard设计它。原型(prototype)单元非常基本,它只有两个标签。姓名标签和日期标签。 当我运行程序时,样式就在那里(字体
我正在尝试填充不可变 JS 映射。给定一个字段数组和一个表单,例如 {form: 'Register', fields: ['name','firstname']} 我想得到类似的东西: { form
我有两个 Mongoose 模型: 1-事件模型: eventSchema = new mongoose.Schema({ name: { type: String, requir
我想以编程方式填充 WPF ListView 。我认为我接近答案但尚未解决,我使用一种方法来填充 ListView , ListView 在 XAML 中看起来像这样
我有以下场景: 用户可以登录网站。用户可以添加/删除投票(有两个选项的问题)。任何用户都可以通过选择任何选项来对民意调查发表意见。 考虑到上述情况,我有三个模型 - Users Polls Optio
这个问题在这里已经有了答案: Capture __LINE__ and __FILE__ without #define (2 个答案) 关闭 3 年前。 所以我有一个要评估结果的函数,如果结果失败
我有一个使用 innerHTML 在表中添加行的函数: function addRowToTable(tblParam) { var tbl =document.getElementById(tb
我是一名优秀的程序员,十分优秀!