variance

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

妖精的绣舞 提交于 2019-12-09 17:44:32
问题 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

Code optimization + Generating sample data based on pre-defined variance

一曲冷凌霜 提交于 2019-12-08 11:35:31
问题 I am generating sample data for running a simulation where I need to take care of variance across the sample. I have written the code but I am not getting the variance as expected. Need some help on how to get this right. Also any suggestions on optimizing the code is most welcome! So to start with I generate a sample data using below code - library("data.table") set.seed(1200) N_Blocks = 100 #My actual data has this around 1500 which take time for below for loop so restricted this to 100 cyc

Type L is in contravariant position in type A => Either[L, B]

你说的曾经没有我的故事 提交于 2019-12-08 07:34:20
问题 I tried to write simple implementation of flatMap for Either sealed trait Either[+L, +R] { def flatMap[B](f: R => Either[L, B]): Either[L, B] = this match { case Left(e) => Left(e) case Right(e) => f(e) } } final case class Right[+A, +B](right: B) extends Either[A, B] final case class Left[+A, +B](left: A) extends Either[A, B] and faced following problem: covariant type L is in contravariant position in type f: R => Either[L, B] of value f, but why is it so? I thought that our type is in

Implicit resolution with covariance

早过忘川 提交于 2019-12-08 06:49:27
问题 Why does the following code work when Foo is invariant, but not when it is covariant? The covariant version of Foo produces a type error saying that in the call of useF1 , the argument has type Foo[T] but F1 is required. A similar error is produced for useF2 . If the variance annotation is removed from Foo , the code works. The pattern match against F1 exposes the fact that T = Int , so that x has type Foo[Int] . The implicit conversion function is used to convert Foo[Int] to F1 in the

EventHandlers and Covariance

北慕城南 提交于 2019-12-07 01:56:56
问题 I've been trying to create a generic event. Basically it should look like this: namespace DelegateTest { class Program { static void Main(string[] args) { var lol = new SomeClass(); lol.SomeEvent += handler; } static void handler(object sender, SomeDerivedClass e) { } } class SomeClass { public delegate void SomeEventDelegate<in T>(object sender, T data); public event SomeEventDelegate<ISomeInterface> SomeEvent; } interface ISomeInterface { } class SomeDerivedClass : ISomeInterface { } } I

Calculate average, variance and standard deviation of two numbers in two different rows/columns with sql / PHP on specific dates

和自甴很熟 提交于 2019-12-06 13:27:20
问题 I have a Database with the following structure: rowid ID startTimestamp endTimestamp subject 1 00:50:c2:63:10:1a ...1000 ...1090 entrance 2 00:50:c2:63:10:1a ...1100 ...1270 entrance 3 00:50:c2:63:10:1a ...1300 ...1310 door1 4 00:50:c2:63:10:1a ...1370 ...1400 entrance . . . With this SQL-Query i can get the average differences between the endTime and the startTime between one row and the following row, sorted by subject and ID, with their min,max,variance and standard deviation: SELECT ID

Calculate variation of IP addresses column using MySQL

纵然是瞬间 提交于 2019-12-06 12:55:31
问题 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

EventHandlers and Covariance

北战南征 提交于 2019-12-05 07:28:45
I've been trying to create a generic event. Basically it should look like this: namespace DelegateTest { class Program { static void Main(string[] args) { var lol = new SomeClass(); lol.SomeEvent += handler; } static void handler(object sender, SomeDerivedClass e) { } } class SomeClass { public delegate void SomeEventDelegate<in T>(object sender, T data); public event SomeEventDelegate<ISomeInterface> SomeEvent; } interface ISomeInterface { } class SomeDerivedClass : ISomeInterface { } } I want to allow the user to pass any delegate which's second parameter is derived from "ISomeInterface."

K means finding elbow when the elbow plot is a smooth curve

て烟熏妆下的殇ゞ 提交于 2019-12-05 05:35:33
I am trying to plot the elbow of k means using the below code: load CSDmat %mydata for k = 2:20 opts = statset('MaxIter', 500, 'Display', 'off'); [IDX1,C1,sumd1,D1] = kmeans(CSDmat,k,'Replicates',5,'options',opts,'distance','correlation');% kmeans matlab [yy,ii] = min(D1'); %% assign points to nearest center distort = 0; distort_across = 0; clear clusts; for nn=1:k I = find(ii==nn); %% indices of points in cluster nn J = find(ii~=nn); %% indices of points not in cluster nn clusts{nn} = I; %% save into clusts cell array if (length(I)>0) mu(nn,:) = mean(CSDmat(I,:)); %% update mean %% Compute

Calculate average, variance and standard deviation of two numbers in two different rows/columns with sql / PHP on specific dates

旧时模样 提交于 2019-12-04 21:57:26
I have a Database with the following structure: rowid ID startTimestamp endTimestamp subject 1 00:50:c2:63:10:1a ...1000 ...1090 entrance 2 00:50:c2:63:10:1a ...1100 ...1270 entrance 3 00:50:c2:63:10:1a ...1300 ...1310 door1 4 00:50:c2:63:10:1a ...1370 ...1400 entrance . . . With this SQL-Query i can get the average differences between the endTime and the startTime between one row and the following row, sorted by subject and ID, with their min,max,variance and standard deviation: SELECT ID,AVG(diff) AS average, AVG(diff*diff) - AVG(diff)*AVG(diff) AS variance, SQRT(AVG(diff*diff) - AVG(diff)