nan

How is NaN handled in Pearson correlation user-user similarity matrix in a recommender system?

╄→гoц情女王★ 提交于 2019-12-22 05:29:50
问题 I am generating a user-user similarity matrix from a user-rating data (particularly MovieLens100K data). Computing correlation leads to some NaN values. I have tested in a smaller dataset: User-Item rating matrix I1 I2 I3 I4 U1 4 0 5 5 U2 4 2 1 0 U3 3 0 2 4 U4 4 4 0 0 User-User Pearson Correlation similarity matrix U1 U2 U3 U4 U5 U1 1 -1 0 -nan 0.755929 U2 -1 1 1 -nan -0.327327 U3 0 1 1 -nan 0.654654 U4 -nan -nan -nan -nan -nan U5 0.755929 -0.327327 0.654654 -nan 1 For computing the pearson

RuntimeWarning: invalid value encountered in maximum

时间秒杀一切 提交于 2019-12-22 04:36:06
问题 Weird behavior (bug??) in numpy. Contrary to the docs, the following code gives a RuntimeWarning: invalid value encountered in fmax a = np.random.uniform(0.1, 0.4, (5, 5)) b = np.random.uniform(0, 3.5, (5, 5)) b[0, 0] = np.nan c = np.fmax(a, b) # Same problem with c = np.maximum(a, b) I'm stuck as I need these NaNs in my arrays and now my functions stop in iPython with this damn warning (ok, they really don't stop but it's rather annoying) EDIT : numpy 1.6.1 ipython 0.13.1 回答1: I get the same

How to check if number is NaN

谁说我不能喝 提交于 2019-12-22 03:50:36
问题 I need to test if a numeric/float value in PostgreSQL is not a number (NaN). Note that "PostgreSQL treats NaN values as equal", so this C++ trick doesn't work. As I'm not seeing any isnan function in PostgreSQL 9.3, here is my best attempt to make one: create or replace function isnan(double precision) returns boolean as $$select $1::text = 'NaN'::text$$ language sql; Is there any better way to test for NaN s? 回答1: Is there any better way to test for NaNs? Simply compare for equality: SELECT

Can float (or double) be set to NaN?

时光毁灭记忆、已成空白 提交于 2019-12-22 01:33:35
问题 Note: Similar to Can an integer be NaN in C++? I understand this has little practical purpose, but can a float or double be set to NaN ? 回答1: The Float object contains a static value, which is a float type, called NaN . So float myFloat = Float.NaN; gives you what you are asking. http://download.oracle.com/javase/6/docs/api/java/lang/Float.html#NaN 回答2: Sure! NaN is a static constant in the Float and Double classes. double x = Double.NaN; 回答3: Yes float f = Float.NaN; See the doc for more

pandas groupby and rolling_apply ignoring NaNs

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 09:31:55
问题 I have a pandas dataframe and I want to calculate the rolling mean of a column (after a groupby clause). However, I want to exclude NaNs. For instance, if the groupby returns [2, NaN, 1], the result should be 1.5 while currently it returns NaN. I've tried the following but it doesn't seem to work: df.groupby(by=['var1'])['value'].apply(pd.rolling_apply, 3, lambda x: np.mean([i for i in x if i is not np.nan and i!='NaN'])) If I even try this: df.groupby(by=['var1'])['value'].apply(pd.rolling

Standard error ignoring NaN in pandas groupby groups

若如初见. 提交于 2019-12-21 09:27:56
问题 I have data loaded into a dataframe with that has a multi index for the columns headers. Currently I've been grouping the data by the columns indices to take the mean of the groups and calculate the 95% confidence intervals like this: from pandas import * import pandas as pd from scipy import stats as st #Normalize to starting point then convert normalized = (data - data.ix[0]) * 11.11111 #Group normalized data based on slope and orientation grouped = normalized.groupby(level=['SLOPE','DEPTH'

Replace the zeros in a NumPy integer array with nan

女生的网名这么多〃 提交于 2019-12-21 07:24:06
问题 I wrote a python script below: import numpy as np arr = np.arange(6).reshape(2, 3) arr[arr==0]=['nan'] print arr But I got this error: Traceback (most recent call last): File "C:\Users\Desktop\test.py", line 4, in <module> arr[arr==0]=['nan'] ValueError: invalid literal for long() with base 10: 'nan' [Finished in 0.2s with exit code 1] How to replace zeros in a NumPy array with nan? 回答1: np.nan has type float : arrays containing it must also have this datatype (or the complex or object

Scikit NaN or infinity error message

你。 提交于 2019-12-21 06:20:32
问题 I'm importing some data from a csv file. The file has nan values flagged with text 'NA'. I import the data with: X = genfromtxt(data, delimiter=',', dtype=float, skip_header=1) I the use this code to replace nan with a previosly calculated column mean. inds = np.where(np.isnan(X)) X[inds]=np.take(col_mean,inds[1]) I then run a couple of checks and get empty arrays: np.where(np.isnan(X)) np.where(np.isinf(X)) Finally I run a scikit classifier: RF = ensemble.RandomForestClassifier(n_estimators

R can't convert NaN to NA

本小妞迷上赌 提交于 2019-12-21 04:28:23
问题 I have a data frame with several factor columns containing NaN 's that I would like to convert to NA 's (the NaN seems to be a problem for using linear regression objects to predict on new data). > tester1 <- c("2", "2", "3", "4", "2", "3", NaN) > tester1 [1] "2" "2" "3" "4" "2" "3" "NaN" > tester1[is.nan(tester1)] = NA > tester1 [1] "2" "2" "3" "4" "2" "3" "NaN" > tester1[is.nan(tester1)] = "NA" > tester1 [1] "2" "2" "3" "4" "2" "3" "NaN" 回答1: Here's the problem: Your vector is character in

Comparing Double.NaN with itself

北慕城南 提交于 2019-12-20 16:10:55
问题 I am stuck trying to find out why these two operations return different values: Double.NaN == Double.NaN returns false Double.NaN.Equals(Double.NaN) returns true I have the answer to the first part but not the second and not to "why are these two comparisons returning different values" 回答1: The reason for the difference is simple, if not obvious. If you use the equality operator == , then you're using the IEEE test for equality. If you're using the Equals(object) method, then you have to