IF & AND conditions not working in Google Sheets - if-statement

I'm not the best in excel so I would like to ask about some conditionals, I'm adding the AND to my original formula that is this one:
=IF(G2>=0.8, "Valid", "Not Valid")
Basically if my value is equal or higher to 0.8 print Valid if not "Not valid" everything fine with that but when I try to add the AND with this formula:
=IF(AND(G2>=0.8, G2<=0.2, "Zero"),"Valid", "Not Valid")
So what I'm trying to do in this formula is that if the value is lower than 0.2 print "Zero", any value between 0.2 to 0.8 will be not valid and everything higher than 0.8 is valid so. I'm not really sure what is missing. This is an image from my sheet:

delete everything in E2:E and use this in E2:
=INDEX(IF((G2:G< 0.2)*(G2:G<>""), "Zero",
IF((G2:G>=0.2)*(G2:G<=0.8), "Not Valid",
IF(G2:G>0.8, "Valid", )))
or try:
=INDEX(IF(G2:G="",,IFERROR(VLOOKUP(G2:G,
{0, "Zero"; 0.2, "Not Valid"; 0.8, "Valid"}, 2, 1)))

Related

i keep getting token rightparen expected error when i try to use if statement on power query editor for powerbi

this is my code
-- if([Discount Band]="None",0,if([Discount Band]="Low",0.01,if([Discount Band]="Medium",0.05,0.1)))
Screenshot of my work:
Your syntax is incorrect, for M/Power Query it is 'if then else' not comma separated, like DAX/Excel. A good example is here
if([Discount Band]="None",0,if([Discount Band]="Low",0.01,if([Discount Band]="Medium",0.05,0.1)))
this should be
if [Discount Band]= "None" then 0 else
if [Discount Band]= "Low" then 0.01 else
if [Discount Band]= "Medium" then 0.05 else 0.1
Hope that helps
It's a syntax error, the if functions in M uses the following format: If...Then...Else
if [Discount Band]="None"
then 0
else if [Discount Band]="Low"
then 0.01
else if [Discount Band]="Medium"
then 0.05
else 0.1

python numpy probability output

using python 2.7 and numpy i want to be able to print test results based on a probablity percentage. based on 10 events i want to print out true if it passed and false if it failed. Below is pseudo code
import numpy as np
probability = .33
i'm struggling how to implement using the probablity variable in determining if a test has passed. So in this case the probablity of a test passing 'True' is 33 percent. The probablity does not change for each iteration. its always going to be .33 percent
Ideally it should return something like this
false
false
fasle
true
false
true
fasle
fasle
true
true.
You could use the built-in random and generate a number between 0 and 1 (uniform distribution, so all numbers between 0 and 1 are "equally likely"). Then test if that number is less than your desired probability:
import random
def uniform_trials(probability, num_trials):
for _ in range(num_trials):
print(probability < random.uniform(0, 1))
Then just call uniform_trials(.33, 10) for your desired example (or any other probability and num_trials you'd like to output).

GaussianNB :- ValueError: The sum of the priors should be 1

What i am trying to do?
I am trying to train the dataset which has 10 labels using GaussianNB classifier but while tunning my gaussianNB prior parameters i am getting this error:-
File "/home/mg/anaconda2/lib/python2.7/site-packages/sklearn/naive_bayes.py", line 367, in _partial_fit
raise ValueError('The sum of the priors should be 1.')
ValueError: The sum of the priors should be 1.
Code for this:-
clf = GaussianNB(priors = [0.08, 0.14, 0.03, 0.16, 0.11, 0.16, 0.07, 0.14, 0.11, 0.0])
You can see the sum is clearly 1 but it showing me this error, can you point the error.
This looks like a pretty bad design-decision within sklearn as they are doing the usual don't compare floating-point numbers stuff (what every computer scientist should know about floating-point arithmetic), which surprises me (as sklearn is usually high-quality code)!
(I don't see any wrong usage on your end, despite using a list. The docs call for an array, not array-like like in many other cases, but their code is doing the array-conversion nonetheless)
Their code:
if self.priors is not None:
priors = np.asarray(self.priors)
# Check that the provide prior match the number of classes
if len(priors) != n_classes:
raise ValueError('Number of priors must match number of'
' classes.')
# Check that the sum is 1
if priors.sum() != 1.0:
raise ValueError('The sum of the priors should be 1.')
# Check that the prior are non-negative
if (priors < 0).any():
raise ValueError('Priors must be non-negative.')
self.class_prior_ = priors
else:
# Initialize the priors to zeros for each class
self.class_prior_ = np.zeros(len(self.classes_),
dtype=np.float64)
So:
You give a list, but their code will create an numpy-array
Therefore np.sum() will be used for summing
There might be fp-math related numerical-errors in summing like in your case
your sum is technically != 1.0; but very close to it!
fp-comparison x == 1.0 is considered bad!
numpy brings np.isclose() which is the usual approach of doing this
Demo:
import numpy as np
priors = np.array([0.08, 0.14, 0.03, 0.16, 0.11, 0.16, 0.07, 0.14, 0.11, 0.0])
my_sum = np.sum(priors)
print('my_sum: ', my_sum)
print('naive: ', my_sum == 1.0)
print('safe: ', np.isclose(my_sum, 1.0))
Output:
('my_sum: ', 1.0000000000000002)
('naive: ', False)
('safe: ', True)
Edit:
As i think that this code is not good, i posted an issue here which you can follow to see if they comply or not.
numpy.random.sample(), which also takes such a vector, is actually doing a fp-safe approach too (numerically more stable summation + epsilon-check; but not using np.isclose()) as seen here.

numpy arange for floating point start & stop

I want numpy to create a full list, given the parameters start, stop and increment, but ran into some troubles:
In[2]: import numpy as np
In[3]: np.arange(2.0, 2.4, 0.2)
Out[3]: array([ 2. , 2.2])
In[4]: np.arange(2.0, 2.6, 0.2)
Out[4]: array([ 2. , 2.2, 2.4, 2.6])
In[5]: np.arange(2.0, 2.8, 0.2)
Out[5]: array([ 2. , 2.2, 2.4, 2.6])
What I actually want is:
array([ 2. , 2.2, 2.4])
Now, I've learned that I should avoid the floating point data type if it comes down to fixed values. I know it would be better to multiply start/stop/increment by 100, but the problem is that I cannot tell, how many decimals the user is going to supply. Is there any way I can still do that with Float or is there a better way to solve this?
Edit:
It works now with the obvious solution of adding 0.0000001 to the end-value. But this looks horrible in my code...I'd hope to fix this nicely somehow
Could you specify which values the user is supposed to enter? For that kind of generation, I think linspace could be better as it includes the end parameter
EDIT: if the user enters start, end, and increment, just use linspace with num = int((end-start)/increment+1) if the exact value of the increment is not critical.
EDIT2:
adapt 1e-4 to the relative error you deem acceptable (you can even add it as a user-defined variable).
eps = 1e-4*(stop-start)
num = int((stop-start)/(incr-eps)+1)
np.linspace(start, stop,num)
this might seem a little longer but if you are keen on using np.arange this is how I worked it out:
decimal_places = decimal.Decimal(str(STEP)).as_tuple().exponent
power_10_multiplier = 10**-decimal_places
MIN = int(MIN*power_10_multiplier)
MAX = int(MAX*power_10_multiplier)
STEP = int(STEP*power_10_multiplier)
arr = np.arange(MIN, MAX + STEP, step=STEP)/power_10_multiplier

Format or Pattern for Decimal Numbers to display on axis on google charts

Good Morning,
When ever we create data table with certain data for Column Chart i.e.
**['Year', '% of ToTal Revenues ', '% of Total orders'],
['Feb12-July12', 0.25, 0.36],
['Aug12-Jan12', 0.58, 0.69],
['Feb13-July14', 0.47, 0.14],
['Aug13-Jan14', 0.62, 0.84]**
in the out put especially on VAxis the graph was displaying 0.1 to 0.98..
but when i a want to append % symbol to the given input values like 0.01%,0.02%,to 0.98% it was converting decimal into natural numbers that for ex 0.65 into 65 so what type of pattern i have to pass forex VAxis:{format:'#.##%'}};
Please Help Me
Thanks in advance
If I undestood right, you want to keep it as decimals instead of 0.5 = 50%. This should do the trick:
vAxis:{format: '#.#\'%\'' }