mean

How to catch the error when inserting a MongoDB document which violates an unique index?

对着背影说爱祢 提交于 2019-11-30 11:14:39
I'm building a MEAN app. This is my Username schema, the username should be unique. var mongoose = require('mongoose'); var Schema = mongoose.Schema; module.exports = mongoose.model('User', new Schema({ username: { type: String, unique: true } })); On my post route I save the user like this: app.post('/authenticate', function(req, res) { var user = new User({ username: req.body.username }); user.save(function(err) { if (err) throw err; res.json({ success: true }); }); }) If I post with the same username again I get this error: MongoError: insertDocument :: caused by :: 11000 E11000 duplicate

三款免费的PHP加速器:APC、eAccelerator、XCache比较[转]

牧云@^-^@ 提交于 2019-11-30 10:38:14
转自: http://www.vpser.net/opt/apc-eaccelerator-xcache.html php加速器的文章,怕以后找不到了,自己记下来,顺便分享给大家。 一、PHP加速器介绍 PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少。 Apache中使用mod_php的请求、响应执行流程: 1、Apache接收请求。 2、Apache传递请求给mod_php。 3、mod_php定位磁盘文件,并加载到内存中。 4、mod_php编译源代码成为opcode树。 5、mod_php执行opcode树。 PHP加速器相应的就是第四步,它的目的就是防止PHP每次请求都重复编译PHP代码,因为在高访问量的网站上,大量的编译往往没有执行速度快呢?所以这里面有个瓶颈就是PHP的重复编译既影响了速度又加载了服务器负载,为了解决此问题,PHP加速器就这样诞生了。 二、PHP加速器安装与配置 1、安装配置APC APC全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”,它是PHP PECL中的一个扩展,好像是facebook在使用它,下面开始安装(ubuntu环境): $wget http://pecl.php.net/get/APC-3.0.19

Panda dataframe conditional .mean() depending on values in certain column

*爱你&永不变心* 提交于 2019-11-30 09:13:56
I'm trying to create a new column which returns the mean of values from an existing column in the same df. However the mean should be computed based on a grouping in three other columns. Out[184]: YEAR daytype hourtype scenario option_value 0 2015 SAT of_h 0 0.134499 1 2015 SUN of_h 1 63.019250 2 2015 WD of_h 2 52.113516 3 2015 WD pk_h 3 43.126513 4 2015 SAT of_h 4 56.431392 I basically would like to have a new column 'mean' which compute the mean of "option value", when "YEAR", "daytype", and "hourtype" are similar. I tried the following approach but without success ... In [185]: o2['premium'

scikit-learn代码实现SVM分类与SVR回归以及调参

你。 提交于 2019-11-30 04:28:21
分类 二分类: from sklearn.model_selection import train_test_split from sklearn.svm import SVC import mglearn.datasets import matplotlib.pyplot as plt #forge数据集是一个二维二分类数据集 X,y=mglearn.tools.make_handcrafted_dataset() X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2, random_state=33) svm=SVC(kernel='rbf',C=10,gamma=0.1,probability=True).fit(X_train,y_train) print(svm.predict(X_test)) #输出分类概率 print(svm.predict_proba(X_test)) print(svm.score(X_test,y_test)) [0 0 1 1 1 0] [[0.91919503 0.08080497] [0.94703815 0.05296185] [0.04718756 0.95281244] [0.08991918 0.91008082] [0.18789225 0

L3-Day19

别来无恙 提交于 2019-11-30 03:57:27
⏰打卡时间:9月20日(周五) 6:00-17:00 训练技巧顺序: 【完全听写法】️【车轮法】️【影子跟读法】 ⏱【练习时间】30 mins 句1: She would always give us nutritious food. 成分划分:She主语 would always give谓语 us间宾 nutritious food直宾. 语法点:动作关系、一般过去时 拓展: nutritious adj 有营养的,富有营养的 语音练习感受:would ~always连读 give ~us连读 句2: She liked serving us meat and potatoes for dinner. 成分划分:She主语 liked谓语 serving us宾语 meat and potatoes for dinner宾补. 语法点:动作关系、一般过去时 拓展: 语音练习感受:serving ~us连读 meat~ and 连读 and 弱读 for弱读 句3: Meat and potatoes can also mean the most important part of something. 成分划分:Meat and potatoes主语 can also mean谓语 the most important part of something宾语从句. 语法点

GR4206 Assignment

雨燕双飞 提交于 2019-11-29 19:19:44
Lab 1 Enter Your Name and UNI Here Sep 13, 2019 Instructions Before you leave lab today make sure that you upload an RMarkdown file to the canvas page (this should have a .Rmd extension) as well as the pdf output after you have knitted the file (this will have a .pdf extension). Note that since you have already knitted this file, you should see both a Lab1_UNI.pdf and a Lab1_UNI.Rmd file in your GR4206 folder. Click on the Files tab to the right to see this. The files you upload to the Canvas page should be updated with commands you provide to answer each of the questions below. You can edit

Aggregate by multiple columns and reshape from long to wide

夙愿已清 提交于 2019-11-29 17:39:09
There are some questions similar to this topic on SO but not exactly like my usecase. I have a dataset where the columns are laid out as shown below Id Description Value 10 Cat 19 10 Cat 20 10 Cat 5 10 Cat 13 11 Cat 17 11 Cat 23 11 Cat 7 11 Cat 14 10 Dog 19 10 Dog 20 10 Dog 5 10 Dog 13 11 Dog 17 11 Dog 23 11 Dog 7 11 Dog 14 What I am trying to do is capture the mean of the Value column by Id, Description. The final dataset would look like this. Id Cat Dog 10 14.25 28.5 11 15.25 15.25 I can do this in a very rough manner not very efficient like this tempdf1 <- df %>% filter(str_detect

How to catch the error when inserting a MongoDB document which violates an unique index?

允我心安 提交于 2019-11-29 16:52:36
问题 I'm building a MEAN app. This is my Username schema, the username should be unique. var mongoose = require('mongoose'); var Schema = mongoose.Schema; module.exports = mongoose.model('User', new Schema({ username: { type: String, unique: true } })); On my post route I save the user like this: app.post('/authenticate', function(req, res) { var user = new User({ username: req.body.username }); user.save(function(err) { if (err) throw err; res.json({ success: true }); }); }) If I post with the

computing the mean for python datetime

好久不见. 提交于 2019-11-29 14:40:10
I have a datetime attribute: d = { 'DOB': pd.Series([ datetime.datetime(2014, 7, 9), datetime.datetime(2014, 7, 15), np.datetime64('NaT') ], index=['a', 'b', 'c']) } df_test = pd.DataFrame(d) I would like to compute the mean for that attribute. Running mean() causes an error: TypeError: reduction operation 'mean' not allowed for this dtype I also tried the solution proposed elsewhere . It doesn't work as running the function proposed there causes OverflowError: Python int too large to convert to C long What would you propose? The result for the above dataframe should be equivalent to datetime

Panda dataframe conditional .mean() depending on values in certain column

对着背影说爱祢 提交于 2019-11-29 14:02:21
问题 I'm trying to create a new column which returns the mean of values from an existing column in the same df. However the mean should be computed based on a grouping in three other columns. Out[184]: YEAR daytype hourtype scenario option_value 0 2015 SAT of_h 0 0.134499 1 2015 SUN of_h 1 63.019250 2 2015 WD of_h 2 52.113516 3 2015 WD pk_h 3 43.126513 4 2015 SAT of_h 4 56.431392 I basically would like to have a new column 'mean' which compute the mean of "option value", when "YEAR", "daytype",