variance

Calculate variation of IP addresses column using MySQL

做~自己de王妃 提交于 2019-12-04 20:14:08
I'm trying to detect people using proxies to abuse my website. Often they will change proxies and so forth. But there is definitely a pattern of them using one proxy address many times. Much more than is normal for legitimate visitors. Usually most accessing of my website is by unique ip addresses that have only visited once or a few times. Not repeatedly. Let's say I have these ip addresses in a column: 89.46.74.56 89.46.74.56 89.46.74.56 91.14.37.249 104.233.103.6 That would mean there are 3 uniques out of 5. Giving a "uniqueness score" of 60%. How would I calculate this efficiently using

How can I simply calculate the rolling/moving variance of a time series in python?

删除回忆录丶 提交于 2019-12-04 17:40:21
问题 I have a simple time series and I am struggling to estimate the variance within a moving window. More specifically, I cannot figure some issues out relating to the way of implementing a sliding window function. For example, when using NumPy and window size = 20: def rolling_window(a, window): shape = a.shape[:-1] + (a.shape[-1] - window + 1, window) strides = a.strides + (a.strides[-1],) return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides) rolling_window(data, 20) np.var

Naive Bayes: the within-class variance in each feature of TRAINING must be positive

柔情痞子 提交于 2019-12-04 04:03:24
When trying to fit Naive Bayes: training_data = sample; % target_class = K8; # train model nb = NaiveBayes.fit(training_data, target_class); # prediction y = nb.predict(cluster3); I get an error: ??? Error using ==> NaiveBayes.fit>gaussianFit at 535 The within-class variance in each feature of TRAINING must be positive. The within-class variance in feature 2 5 6 in class normal. are not positive. Error in ==> NaiveBayes.fit at 498 obj = gaussianFit(obj, training, gindex); Can anyone shed light on this and how to solve it? Note that I have read a similar post here but I am not sure what to do?

Variance rules in C#

断了今生、忘了曾经 提交于 2019-12-04 03:09:08
The Exact rules for variance validity are a bit vague and not specific. I'm going to list the rules for what makes a type valid-covariantly, and attach some queries and personal annotations to each of those rules. A type is valid covariantly if it is: 1) a pointer type, or a non-generic type. Pointers and non-generic types are not variant in C#, except for arrays and non-generic delegates. Generic classes, structs and enums are invariant. Am I right here? 2) An array type T[] where T is valid covariantly. So this means that if the element type T of an array T[] is covariant (reference or array

Random number with specific variance in Python

。_饼干妹妹 提交于 2019-12-03 22:23:11
问题 In a Python program, I need to generate normally-distributed random numbers with a specific, user-controlled variance. How can I do this? 回答1: import math from random import gauss my_mean = 0 my_variance = 10 random_numbers = [gauss(my_mean, math.sqrt(my_variance)) for i in range(100)] This gets you 100 normally-distributed random numbers with mean 0 and variance 10. 回答2: Use random.normalvariate (or random.gauss if you don't need thread-safety), and set the sigma argument to the square root

How can I simply calculate the rolling/moving variance of a time series in python?

主宰稳场 提交于 2019-12-03 11:18:13
I have a simple time series and I am struggling to estimate the variance within a moving window. More specifically, I cannot figure some issues out relating to the way of implementing a sliding window function. For example, when using NumPy and window size = 20: def rolling_window(a, window): shape = a.shape[:-1] + (a.shape[-1] - window + 1, window) strides = a.strides + (a.strides[-1],) return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides) rolling_window(data, 20) np.var(rolling_window(data, 20), -1) datavar=np.var(rolling_window(data, 20), -1) Perhaps I am mistaken

What's the difference between A<:B and +B in Scala?

我怕爱的太早我们不能终老 提交于 2019-12-03 00:04:36
问题 What's the difference between [A <: B] and [+B] in Scala? 回答1: Q[A <: B] means that class Q can take any class A that is a subclass of B . Q[+B] means that Q can take any class, but if A is a subclass of B , then Q[A] is considered to be a subclass of Q[B] . Q[+A <: B] means that class Q can only take subclasses of B as well as propagating the subclass relationship. The first is useful when you want to do something generic, but you need to rely upon a certain set of methods in B . For example

How to calculate weight to minimize variance?

六月ゝ 毕业季﹏ 提交于 2019-12-02 05:44:58
问题 given several vectors: x1 = [3 4 6] x2 = [2 8 1] x3 = [5 5 4] x4 = [6 2 1] I wanna find weight w1, w2, w3 to each item, and get the weighted sum of each vector: yi = w1*i1 + w2*i2 + w3*i3 . for example, y1 = 3*w1 + 4*w2 + 6*w3 to make the variance of these values(y1, y2, y3, y4) to be minimized. notice: w1, w2, w3 should > 0, and w1 + w2 + w3 = 1 I don't know what kind of problems it should be... and how to solve it in python or matlab? 回答1: You can start with building a loss function stating

Calculating variance with large numbers

北城余情 提交于 2019-12-02 05:36:13
问题 I haven't really used variance calculation that much, and I don't know quite what to expect. Actually I'm not too good with math at all. I have a an array of 1000000 random numeric values in the range 0-10000. The array could grow even larger, so I use 64 bit int for sum. I have tried to find code on how to calc variance, but I don't know if I get correct output. The mean is 4692 and median is 4533. I get variance 1483780.469308 using the following code: // size is the element count, in this

Calculating grouped variance from a frequency table in R

我与影子孤独终老i 提交于 2019-12-02 05:32:58
How can I, in R calculate the overall variance and the variance for each group from a dataset that looks like this (for example): Group Count Value A 3 5 A 2 8 B 1 11 B 3 15 I know to calculate the variance as a whole, ignoring the groups I would do: var(rep(x$Value, x$Count)), but how do I automatically calculate the variance for each group accounting for the frequency? E.g., the variance for group A, group B, etc.,.. I would like my output to have the following headers: Group, Total Count, Group Variance I have also reviewed this link; R computing mean, median, variance from file with