floating-accuracy

Merging dataframes with all.equal on numeric(float) keys?

一世执手 提交于 2020-01-07 01:22:13
问题 I have two data frames I want to merge based on a numeric value, however I am having trouble with floating point accuracy. Example: > df1 <- data.frame(number = 0.1 + seq(0.01,0.1,0.01), letters = letters[1:10]) > df2 <- data.frame(number = seq(0.11,0.2,0.01), LETTERS = LETTERS[1:10]) > (merged <- merge(df1, df2, by = "number", all = TRUE)) number letters LETTERS 1 0.11 a A 2 0.12 <NA> B 3 0.12 b <NA> 4 0.13 c C 5 0.14 d D 6 0.15 <NA> E 7 0.15 e <NA> 8 0.16 f F 9 0.17 g G 10 0.18 h H 11 0.19

Calculate the Confusion Matrix in different columns in panda frame?

天涯浪子 提交于 2020-01-06 06:54:49
问题 I have a dataframe with 3000 rows and 3 columns as follows: 0 col1 col2 col3 ID1 1 0 1 Id2 1 1 0 Id3 0 1 1 Id4 2 1 0 Id5 2 2 3 … .. .. .. Id3000 3 1 0 In this data frame, the value of each column and row refers to a result of a prediction problem as follows: 0 means TP, 1 means FP, 2 refers to TN and 3 points to FN in each column. So I want to calculate the accuracy of each column. something like this: Accuracy result: col1 col2 col3 0.67 0.68 0.79 Any idea that I can calculate the important

Calculate the Confusion Matrix in different columns in panda frame?

隐身守侯 提交于 2020-01-06 06:54:29
问题 I have a dataframe with 3000 rows and 3 columns as follows: 0 col1 col2 col3 ID1 1 0 1 Id2 1 1 0 Id3 0 1 1 Id4 2 1 0 Id5 2 2 3 … .. .. .. Id3000 3 1 0 In this data frame, the value of each column and row refers to a result of a prediction problem as follows: 0 means TP, 1 means FP, 2 refers to TN and 3 points to FN in each column. So I want to calculate the accuracy of each column. something like this: Accuracy result: col1 col2 col3 0.67 0.68 0.79 Any idea that I can calculate the important

Some questions about floating points

回眸只為那壹抹淺笑 提交于 2020-01-05 04:58:10
问题 I'm wondering if a number is represented one way in a floating point representation, is it going to be represented in the same way in a representation that has a larger size. That is, if a number has a particular representation as a float , will it have the same representation if that float is cast to a double and then still the same when cast to a long double . I'm wondering because I'm writing a BigInteger implementation and any floating point number that is passed in I am sending to a

PHP Printf As Float Precision

北城以北 提交于 2020-01-04 16:56:49
问题 I am attempting to use PHP's printf function to print out a user's storage capacity. The full formula looks something like this: echo printf("%.02f", ($size/(1024*1024))) . " GB"; Given that $size == (10 * 1024 * 1024) , this should print out 10.00 GB But it doesn't. It prints 10.04 GB . Furthermore, echo printf("%.02f", 10) results in 10.04 What?! In giving it an integer to convert to a float, it converts 10 to 10.00000009. How can this be remedied? Obviously, one solution would be to print

Why does parseFloat() in JavaScript produce consisant but unitinutive results?

故事扮演 提交于 2020-01-04 05:53:22
问题 While providing an answer to a question about adding a method that increments a float value in an html input , I came across what I know is a common issue with IEEE Floating point math. This is an example (with a demo) of what I am seeing: <input type="text" name="BoqTextBox" id="BoqTextBox" value="0.001" /> <input type="Button" id='AddButton' value="+" /> <script> $('#AddButton').on('click', function () { var input = $('#BoqTextBox'); input.val(parseFloat(input.val(), 10) + 1); }) </script>

Floating point rounding in C

China☆狼群 提交于 2020-01-04 05:49:09
问题 I've run into some weird rounding behaviour with floats. The code below demonstrates the problem. What is the best way to solve this? I've been looking for solutions but haven't had much luck. #include<stdio.h> int main(void) { float t; t = 5592411; printf("%f\n", 1.5*t); t *= 1.5; printf("%f\n", t); return 0; } The code above should print out the same value, but I get this on my setup using GCC 4.7.2: 8388616.500000 8388616.000000 If I use a calculator, I get the first value, so I assume the

Does ruby calculate floats wrong? [duplicate]

时光毁灭记忆、已成空白 提交于 2020-01-04 05:24:09
问题 This question already has answers here : Addition error with ruby-1.9.2 [duplicate] (2 answers) Closed last year . Whats wrong here? (ruby version: 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0] x = 523.8 w = 46.9 xm = x + w assert_equal w, (xm - x) # FAILS with: <46.9> expected but was <46.89999999999998> 回答1: From The Floating-Point Guide: Why don’t my numbers, like 0.1 + 0.2 add up to a nice round 0.3, and instead I get a weird result like 0.30000000000000004? Because

Division of float numbers in JavaScript

梦想与她 提交于 2020-01-04 05:06:07
问题 I'm trying to divide screenwidth by a variable in order to draw equally spaced UI parts in webview. However, when the variable is 3, 100 / 3 results 33.3333333333333336 in JavaScript, and the third part cannot be drawn as intended because the sum of the quotients is bigger than 100%, I gusss. Is there any nice workaround for this problem? 回答1: You can specify the precision of the division: var width = (100 / 3).toPrecision(3); 回答2: The best you can do is get as close as possible: (100 / 3)

Floating Point Precision Error

耗尽温柔 提交于 2020-01-03 13:15:08
问题 I am having problem with the LISP expression below. There is floating precision error while doing sum for floating point numbers. CL-USER> (+ -380 -158.27 -35.52) Actual: -573.79004 Expected: -573.79000 Please suggest me how can I achieve the expected result in LISP (I am using Lispworks). 回答1: Floats are not exact Floats represent a subset of mathematical reals with certain precision , they are not exact numbers. Round off errors are inevitable . The ANSI Common Lisp standard provides for 4(