Hot answers tagged

23 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 ...
Rudra Mohan's user avatar
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 ...
Tasos's user avatar
  • 3,910
15 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. ...
aerijman's user avatar
  • 303
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 ...
Yohanes Alfredo's user avatar
13 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: ...
jottbe's user avatar
  • 439
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 ...
LMSharma's user avatar
  • 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 <...
n1k31t4's user avatar
  • 14.8k
11 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 ...
bkshi's user avatar
  • 2,225
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))
GrozaiL's user avatar
  • 374
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 <...
Dotiyal's user avatar
  • 81
7 votes
Accepted

Can't understand this simple matrix multiplication in python

It works for me. ...
Siong Thye Goh's user avatar
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: ...
Green Falcon's user avatar
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 ...
Giannis Krilis's user avatar
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. ...
Aditya's user avatar
  • 2,460
6 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: ...
M0nZDeRR's user avatar
  • 385
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 ...
Robin's user avatar
  • 1,337
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 ...
JahKnows's user avatar
  • 8,846
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 - ...
n1k31t4's user avatar
  • 14.8k
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 ...
Itamar Mushkin's user avatar
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, <...
Umar.H's user avatar
  • 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 ...
Kirill Fedyanin's user avatar
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 ...
David Marx's user avatar
  • 3,228
4 votes
Accepted

Scatter plot for binary class dataset with two features in python

Found the answer. Thank you @Aditya ...
Nitish's user avatar
  • 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 ...
Robin's user avatar
  • 1,337
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 ...
nazz's user avatar
  • 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 ...
n1k31t4's user avatar
  • 14.8k
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 ...
Brian Spiering's user avatar
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 ...
Esmailian's user avatar
  • 9,252
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. "...
bradS's user avatar
  • 1,565
4 votes

Python: multiplication of sparse matrices slower in csr_matrix than numpy

Here, you do not time only the time taken to make the matrix multiplication but also the time taken to convert your matrix from dense to sparse. If you convert your matrix before the timing starts, ...
Robin Nicole's user avatar

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