现在,我能够在我的图像数据上训练和测试神经网络。我希望能够从 DirectoryIterator train_generator 中提取图像数据和相应的标签,以便我可以对这些数据进行洗牌并执行交叉验证。有没有办法提取(如果需要,还可以格式化)这些数据?
from keras.preprocessing.image import ImageDataGenerator
img_width, img_height = 150, 150
train_data_dir = '/train'
datagen = ImageDataGenerator(rescale=1./255) #rescales [0,1]
train_generator = datagen.flow_from_directory(train_data_dir, target_size=(img_width, img_height), shuffle=True, batch_size=32, class_mode='binary')
#I want to do something like (X, Y) = train_generator.getData()
Run Code Online (Sandbox Code Playgroud) 我的理解是,在使用时useState(),我们应该这样声明数组:
const [someBooleanValue, setSomeBooleanValue] = useState(false)
Run Code Online (Sandbox Code Playgroud)
代替
let [someBooleanValue, setSomeBooleanValue] = useState(false)
Run Code Online (Sandbox Code Playgroud)
通常,const用于不会改变的变量。在这里,someBooleanValue将发生变化。const在这种情况下,发生了什么允许我们使用关键字?
假设一周前我生成一个2015-10-10T10:00:00的LocalDateTime.此外,我们假设我生成了当前的时区ID
TimeZone timeZone = TimeZone.getDefault();
String zoneId = timeZone.getId(); // "America/Chicago"
Run Code Online (Sandbox Code Playgroud)
我的zoneId是"America/Chicago".
有没有一种简单的方法可以将我的LocalDateTime转换为时区id"America/New_York"(即所以我更新的LocalDateTime将是2015-10-10T11:00:00)?
更重要的是,无论我在哪个时区,有没有办法可以将我的LocalDateTime转换为东部时间(即带有zoneId"America/New_York"的时区)?我特意寻找一种方法来处理过去生成的任何LocalDateTime对象,而不一定是当前时间.
我有一个文件,myFunction.ts定义并导出一个函数:
export function MyFunction() {
return async (ctx: Koa.Context) => {
//some work happens in here
};
}
Run Code Online (Sandbox Code Playgroud)
该函数在 Koa 中间件文件中被调用,并继承了ctx之前的中间件。在这种情况下,如何创建一个模拟ctx来进行测试?MyFunction()
我有一个包含功能的应用程序事件监听器:
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
如何编写一个单元测试来模拟ContextRefreshedEvent(例如执行我的jar),并测试onApplicationEvent函数是否已完成应做的工作?
我有X_train和y_train作为2 numpy.ndarrays的大小分别为(32561,108)和(32561,)。
每次我调用适合GaussianProcessClassifier的函数时,都会收到内存错误。
>>> import pandas as pd
>>> import numpy as np
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import RBF
>>> X_train.shape
(32561, 108)
>>> y_train.shape
(32561,)
>>> gp_opt = GaussianProcessClassifier(kernel=1.0 * RBF(length_scale=1.0))
>>> gp_opt.fit(X_train,y_train)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 613, in fit
self.base_estimator_.fit(X, y)
File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 209, in fit
self.kernel_.bounds)]
File "/home/retsim/.local/lib/python2.7/site-packages/sklearn/gaussian_process/gpc.py", line 427, in _constrained_optimization
fmin_l_bfgs_b(obj_func, initial_theta, bounds=bounds)
File "/home/retsim/anaconda2/lib/python2.7/site-packages/scipy/optimize/lbfgsb.py", line 199, in fmin_l_bfgs_b
**opts) …Run Code Online (Sandbox Code Playgroud) 在训练 Ridge 分类器时,我可以像这样执行 10 折交叉验证:
clf = linear_model.RidgeClassifier()
n_folds = 10
scores = cross_val_score(clf, X_train, y_train, cv=n_folds)
scores
array([0.83236107, 0.83937346, 0.84490172, 0.82985258, 0.84336609,
0.83753071, 0.83753071, 0.84213759, 0.84121622, 0.84398034])
Run Code Online (Sandbox Code Playgroud)
如果我想再次执行 10 折交叉验证,我使用:
scores = cross_val_score(clf, X_train, y_train, cv=n_folds)
Run Code Online (Sandbox Code Playgroud)
我最终得到了相同的结果。
因此,似乎两次数据都以相同的方式拆分。有没有办法在每次执行交叉验证时将数据随机划分为 n_folds?
我有一个这样的csv:
this is the first column, this is the 2nd,
firstVal, secondVal
david, baseball
jon, soccer
Run Code Online (Sandbox Code Playgroud)
我想将其转换为:
[{firstVal:david, secondVal:baseball},{firstVal:jon,secondVal:soccer}]
Run Code Online (Sandbox Code Playgroud)
我的 csv 中的第一行是元数据(基本上只是实际列标题的描述——firstVal 和 secondaryVal),我不想将其包含在 json 中。我试过了:
csvtojson({noheader: true}).fromFile(csvFilePath)//...
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。如何忽略第一行进行此转换?
说我有这段代码:
q = PriorityQueue()
a = ((1,1), 10, 0)
b = ((2,2), 99, 200)
q.push(a, 1)
q.push(b, 2)
Run Code Online (Sandbox Code Playgroud)
我想检查元素(1,1)是否存在于队列中的任何元组中。有没有办法做到这一点?
python ×4
java ×2
javascript ×2
scikit-learn ×2
csvtojson ×1
datetime ×1
ecmascript-6 ×1
jestjs ×1
junit ×1
keras ×1
koa ×1
middleware ×1
mocking ×1
npm ×1
pandas ×1
queue ×1
reactjs ×1
spring ×1
testing ×1
timezone ×1
unit-testing ×1