mean

Angular 2 , MEAN Stack : Receiving JSON instead of HTML

十年热恋 提交于 2019-11-27 04:52:19
问题 I'm adding a route to Angular 2 Full Stack repo named " dog" there is no error in command line and data loades fine in table there is 2 Components cat : HomeComponent , path ' ' dog : DogComponent , path '/dog' but when i refresh the page i get the raw JSON instead of HTML app.js var express = require('express'); var path = require('path'); var morgan = require('morgan'); // logger var bodyParser = require('body-parser'); var app = express(); app.set('port', (process.env.PORT || 3000)); app

z-Scores(standard deviation and mean) in PHP

点点圈 提交于 2019-11-27 04:27:45
问题 I am trying to calculate Z-scores using PHP. Essentially, I am looking for the most efficient way to calculate the mean and standard deviation of a data set (PHP array). Any suggestions on how to do this in PHP? I am trying to do this in the smallest number of steps. 回答1: to calculate the mean you can do: $mean = array_sum($array)/count($array) standard deviation is like so: // Function to calculate square of value - mean function sd_square($x, $mean) { return pow($x - $mean,2); } // Function

Calculate mean across dimension in a 2D array

坚强是说给别人听的谎言 提交于 2019-11-27 03:29:12
I have an array a like this: a = [[40, 10], [50, 11]] I need to calculate the mean for each dimension separately, the result should be this: [45, 10.5] 45 being the mean of a[*][0] and 10.5 the mean of a[*][1] . What is the most elegant way of solving this without using a loop? a.mean() takes an axis argument: In [1]: import numpy as np In [2]: a = np.array([[40, 10], [50, 11]]) In [3]: a.mean(axis=1) # to take the mean of each row Out[3]: array([ 25. , 30.5]) In [4]: a.mean(axis=0) # to take the mean of each col Out[4]: array([ 45. , 10.5]) Or, as a standalone function: In [5]: np.mean(a,

How to unscale the coefficients from an lmer()-model fitted with a scaled response

送分小仙女□ 提交于 2019-11-27 02:24:57
问题 I fitted a model in R with the lmer() -function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the fixed-effect coefficients with fixef(mod) : > fixef(mod) (Intercept) X1 X2 X3 X4 0.08577525 -0.16450047 -0.15040043 -0.25380073 0.02350007 It is quite easy to calculate the means by hand from the fixed-effects coefficients. However, I want them to be unscaled and I am unsure how to do this exactly. I am aware that

How can I get xtabs to calculate means instead of sums in R?

a 夏天 提交于 2019-11-27 02:19:32
问题 I have a data frame where each line represents an individual. That data frame has two variables: age and year. I want to make a table of average ages per year. How can I do it? The best I could come up with was xtabs(age ~ year, dataframe) , but this gives me the sum of ages per year. 回答1: Use aggregate : xtabs(hp~cyl+gear,aggregate(hp~cyl+gear,mtcars,mean)) gear cyl 3 4 5 4 97.0000 76.0000 102.0000 6 107.5000 116.5000 175.0000 8 194.1667 0.0000 299.5000 回答2: Have a look at the plyr package,

Pandas: using groupby to get mean for each data category

℡╲_俬逩灬. 提交于 2019-11-26 22:06:32
问题 I have a dataframe that looks like this: >>> df[['data','category']] Out[47]: data category 0 4610 2 15 4610 2 22 5307 7 23 5307 7 25 5307 7 ... ... ... Both data and category are numeric so I'm able to do this: >>> df[['data','category']].mean() Out[48]: data 5894.677985 category 13.805886 dtype: float64 And i'm trying to get the mean for each category. It looks straight forward but when I do this: >>> df[['data','category']].groupby('category').mean() or >>> df.groupby('category')['data']

多项式回归

狂风中的少年 提交于 2019-11-26 21:13:50
目录 多项式回归 一、多项式回归 二、scikit-learn中的多项式回归 三、关于PolynomialFeatures 四、sklearn中的Pipeline 五、过拟合和欠拟合 六、解决过拟合问题 七、透过学习曲线看过拟合 我是尾巴 多项式回归 直线回归研究的是一个依变量与一个自变量之间的回归问题。 研究一个因变量与一个或多个自变量间多项式的回归分析方法,称为多项式回归(Polynomial Regression)多项式回归模型是线性回归模型的一种。 多项式回归问题可以通过变量转换化为多元线性回归问题来解决。 一、多项式回归 import numpy as np import matplotlib.pyplot as plt x = np.random.uniform(-3, 3, size=100) X = x.reshape(-1, 1) y = 0.5 + x**2 + x + 2 + np.random.normal(0, 1, size=100) plt.scatter(x, y) plt.show() 如果直接使用线性回归,看一下效果: from sklearn.linear_model import LinearRegression lin_reg = LinearRegression() lin_reg.fit(X, y) y_predict = lin

np.mean() vs np.average() in Python NumPy?

喜你入骨 提交于 2019-11-26 18:54:56
问题 I notice that In [30]: np.mean([1, 2, 3]) Out[30]: 2.0 In [31]: np.average([1, 2, 3]) Out[31]: 2.0 However, there should be some differences, since after all they are two different functions. What are the differences between them? 回答1: np.average takes an optional weight parameter. If it is not supplied they are equivalent. Take a look at the source code: Mean, Average np.mean: try: mean = a.mean except AttributeError: return _wrapit(a, 'mean', axis, dtype, out) return mean(axis, dtype, out)

how to calculate mean/median per group in a dataframe in r [duplicate]

社会主义新天地 提交于 2019-11-26 17:48:21
This question already has an answer here: Mean per group in a data.frame [duplicate] 8 answers I have a dataframe recording how much money a costomer spend in detail like the following: custid, value 1, 1 1, 3 1, 2 1, 5 1, 4 1, 1 2, 1 2, 10 3, 1 3, 2 3, 5 How to calcuate the charicteristics using mean,max,median,std, etc like the following? Use some apply function? And how? custid, mean, max,min,median,std 1, .... 2,.... 3,.... To add to the alternatives, here's summaryBy from the "doBy" package, with which you can specify a list of functions to apply. library(doBy) summaryBy(value ~ custid,

Generate random numbers with fixed mean and sd

你。 提交于 2019-11-26 17:39:12
问题 When generating random numbers in R using rnorm (or runif etc.), they seldom have the exact mean and SD as the distribution they are sampled from. Is there any simple one-or-two-liner that does this for me? As a preliminary solution, I've created this function but it seems like something that should be native to R or some package. # Draw sample from normal distribution with guaranteed fixed mean and sd rnorm_fixed = function(n, mu=0, sigma=1) { x = rnorm(n) # from standard normal distribution