Hot answers tagged

20 votes

How to include labels in sns heatmap

I got your problem like this way: You want to show labels on the x and y-axis on the seaborn heatmap. So for that, sns.heatmap() function has two parameters which ...
17 votes
Accepted

How to remove outliers using box-plot?

Seaborn uses inter-quartile range to detect the outliers. What you need to do is to reproduce the same function in the column you want to drop the outliers. It's quite easy to do in Pandas. If we ...
  • 3,840
14 votes
Accepted

Convert Numpy array with 'n' and 'y' into integer array of 0 and 1

It is quite trivial (X=='y').astype(int) Should do the trick. It simply converts your array to True or False according to your requirements and then astype will ...
12 votes
Accepted

how to check all values in particular column has same data type or not?

You can get the type of the entries of your column with map: df['ABC'].map(type) So to filter on all values, which are not stored as str, you can use: ...
  • 411
11 votes

How to deal with TypeError: ufunc 'isnan' not supported for the input types

There may be column of type object in your dataFrame. Remove it or convert it into float,int etc. if possible From Documentation of Seaborn: data : rectangular dataset 2D dataset that can be ...
  • 111
11 votes
Accepted

How to replace NaN values for image data?

Given you have images stretched out as columns in a table with ~48,500 rows, I am assuming you have the raw images that are 220x220 in dimension. You can use a function available via OpenCV called <...
  • 14.4k
11 votes

How to remove outliers using box-plot?

If you need to remove outliers and you need it to work with grouped data, without extra complications, just add showfliers argument as False in the function call. ...
  • 263
9 votes

Python - Converting 3D numpy array to 2D

I suggest you to visit this link also for this case would work np.reshape((-1,2))
  • 374
9 votes
Accepted

How to determine input shape in keras?

The number of rows in your training data is not part of the input shape of the network because the training process feeds the network one sample per batch (or, more precisely, batch_size samples per ...
  • 2,175
8 votes

How to include labels in sns heatmap

Here's how we can add simple X-Y labels in sns heatmap: s = sns.heatmap(cm_train, annot=True, fmt='d', cmap='Blues') s.set(xlabel='X-Axis', ylabel='Y-Axis') OR <...
  • 81
7 votes
Accepted

Can't understand this simple matrix multiplication in python

It works for me. ...
7 votes
Accepted

is there a way to normalize [-3,1] to ${\begin{bmatrix} \dfrac{-3}{\sqrt{10}}\\ \dfrac{1}{\sqrt{10}}\\ \end{bmatrix}}$ with python?

You have already computed that, but you've not bound the output to a variable, also called name in python. Try the following snippet: ...
  • 13.7k
7 votes

Convert Numpy array with 'n' and 'y' into integer array of 0 and 1

You could use the following code: X[X=='y'] = 1 X[X=='n'] = 0 This replaces the indexes of 'y' with ...
6 votes

Scatter plot for binary class dataset with two features in python

One approach is to plot the data as a scatter plot with a low alpha, so you can see the individual points as well as a rough measure of density. ...
  • 2,420
5 votes
Accepted

Normalize matrix in Python numpy

nazz's answer doesn't work in all cases and is not a standard way of doing the scaling you try to perform (there are an infinite number of possible ways to scale to [-1,1] ). I assume you want to ...
  • 1,307
5 votes
Accepted

How can I combine two single-column datasets into a single Pandas data frame?

I would import the datasets in pandas separately, mold them as you please, and then you can use the pd.concat function. This will assume that the instances are ...
  • 8,698
5 votes

How feed a numpy array in batches in Keras

You should implement a generator and feed it to model.fit_generator(). Your generator may look like this: ...
  • 375
5 votes
Accepted

How can I count the number of matching zero elements between two numpy arrays?

You can compare the predictions with the expected results directly, using simple comparisons, in this case just ==. This returns boolean values - ...
  • 14.4k
5 votes
Accepted

Count the max number of consecutive 1 and 0 in Pandas Dataframe

To check if a value has changed, you can use .diff and check if it's non-zero with .ne(0) (the ...
5 votes

Count the max number of consecutive 1 and 0 in Pandas Dataframe

For this sort of problem you can use np.where and multiple boolean expressions to get your answer. #1 We need to test if the column is equal to your target values, <...
  • 182
5 votes
Accepted

Which is meant by +/-9.2e18 years in timespan?

From the documentation you referred: "The length of the span is the range of a 64-bit integer times the length of the date or unit." 64 bit integer has values from ...
4 votes
Accepted

Training a Convnet on 300GB data

You don't need to load the whole dataset into memory at once. The only data you need in memory are the samples in a single training batch. Use the fit_generator ...
  • 3,128
4 votes
Accepted

Scatter plot for binary class dataset with two features in python

Found the answer. Thank you @Aditya ...
  • 91
4 votes

Fill missing values AND normalise

I don't understand why you would like to fill values with zeros ! This would basically mean, "this guy, who is 170 cm tall, weights 0 kg" and would fool your network. In my opinion, you have two ...
  • 1,307
4 votes

Normalize matrix in Python numpy

Suppose you have an array arr. You can normalize it like this: arr = arr - arr.mean() arr = arr / arr.max() You first ...
  • 91
4 votes
Accepted

Numpy element wise comparison for a particular value in two arrays

There are two ways I'll show you (there are probably a lot more using NumPy): First method: chaining operations You can use "masking" followed by the comparison and finally a sum operation: We want ...
  • 14.4k
4 votes

Fast way of computing covariance matrix of nonstationary kernel in Python

I still would apply numpy's covaranice function using numpy.apply_along_axis ...
4 votes

SVM SMOTE fit_resample() function runs forever with no result

This is expected and is not related to SMOTE sampling. The computational complexity of non-linear SVM is on the order of $O(n^2)$ to $O(n^3)$ where $n$ is the number of samples. This means that if it ...
  • 8,987
4 votes
Accepted

Is numpy.corrcoef() enough to find correlation?

On a side note, I don't think correlation is the correct measure of relation for you to be using, since Survived is technically a binary categorical variable. "...
  • 1,527
4 votes

Ways to simulate weather data over several periods (Python or R)?

What about creating a Pandas DataFrame and adding a new column such as "Temp_simulated" and simulate the temperature?
  • 1,027

Only top scored, non community-wiki answers of a minimum length are eligible