Skip to main content

Questions tagged [numpy]

NumPy is the fundamental package for scientific computing with Python.

Filter by
Sorted by
Tagged with
2 votes
1 answer
108 views

Numpy implementation of the Quantile function [duplicate]

I am trying to wrap my head around the implementation of the quantile function for finite samples and, specifically, in numpy (main reason to do this: I am working ...
non87's user avatar
  • 33
2 votes
1 answer
79 views

Compute R Squared by Fixing Betas for Multi Linear Regression without Intercept results in a large R Square

I want to fix the betas in multi linear regression based on some data I have, which leads to a RSquare value less than 0% and greater than 100 % based on the projection approach mentioned in ...
godimedia's user avatar
  • 123
1 vote
1 answer
27 views

Why is my learning rate optimization to pure NumPy implementation of Linear Regression so ineffective?

After creating a simple linear regression model in numpy, I found that changing step size / learning rate was not effective in improving the accuracy of the model, or the speed of convergence. Notice ...
Jawad's user avatar
  • 11
0 votes
0 answers
20 views

Why doesn't my numpy code for generating correlated, normally distributed variables preserve the covariance?

I'm trying to generate random variables whose correlation matches some existing data. My coding skills are good, my statistics, not so much... I'm trying to follow this this answer. I know that... ....
MemoryWrangler's user avatar
0 votes
0 answers
120 views

Exploding coefficients in a Linear Regression Model with single input

This is my first post here, so tips are appreciated for future posts! For homework in my CS course I wanted to build a very simple Linear Regression Model (although this was not explicitly required) ...
Florian Ott's user avatar
0 votes
2 answers
44 views

A simple probability model for an epidemic simulation

I'm creating a epidemic simulation program in Python, but I'm stuck trying to determine the probability of being infected (if exposed). I have an m x n grid with 0's and '1 (0's represent healty cells,...
user3306199's user avatar
0 votes
0 answers
27 views

How to subset a binary matrix to maximize the number of unique elements while minimizing duplicates?

I’m trying to optimize a matrix by subsetting rows and then performing a calculation on the subsetted rows. The calculation is representing each of the columns exactly once and having as few ...
O.rka's user avatar
  • 1,472
1 vote
0 answers
26 views

Construct a symmetric confidence interval for the acceleration coefficient [closed]

A machine model is tested in the factory to check the acceleration coefficient. The experiment selects n machines of this model and measures the distance traveled by the machine in 38 seconds. It is ...
Joker221's user avatar
0 votes
1 answer
147 views

How to interpret NearestNeighbor results obtained using cosine similarity for tf-idf vectors

Why is the top result obtained using cosine similarity extremely close to 0 not the expected 1? That implies complete orthogonality. Data: 100k documents/rows with 2000 features(TF_IDF values of ...
Sint's user avatar
  • 111
2 votes
0 answers
184 views

normalizing euclidean distance

I asked a question in SO but was told it is more appropriate here. I'm trying to compute the euclidean distance with vectors of different lengths. ...
HappyPy's user avatar
  • 143
4 votes
1 answer
2k views

How do you sample from a half-normal distribution in Python? [closed]

I would like to generate samples from a half normal distribution. numpy's random number generator allows you to sample from many distributions. Here's an example for the normal distribution. However, ...
bbrame's user avatar
  • 155
0 votes
1 answer
164 views

Fisk distribution in SciPy

According to Wikipedia, the Fisk distribution has two parameters, scale $\alpha$, and shape $\beta$. However, SciPy has only c as the shape parameter. If I am given ...
yujaiyu's user avatar
  • 103
1 vote
2 answers
804 views

Python/numpy - conditional sampling of variables, distribution of subsequent value is based on result of previous value

I am trying to generate a random sample of multiple variables which are loosely related to each other. Meaning that "allowed" values of some variables depend on the value which is set for ...
Maksim Khaitovich's user avatar
1 vote
0 answers
196 views

How to calculate the equilibrium (initial probability) for second order HMM in python?

I have a transition matrix looks like: ...
StaEx_G's user avatar
  • 113
0 votes
0 answers
227 views

Generating multivariate random variable with normal and exponential marginals

I have a collection of data points of the form $[U, V, X, Y]$, where $U$ ~ $N(\mu_1, \sigma_1)$; $V$ ~ $N(\mu_2, \sigma_2)$; $X$ ~ $exp(\lambda_1)$; and $Y$ ~ $exp(\lambda_2)$, and I am looking to ...
Pistol Pete's user avatar
1 vote
0 answers
137 views

Logistic regression with SGD getting low error with high learning rate

The thing is that I am implementing LR with SGD. Here is my cross error function: ...
Dazckel's user avatar
  • 81
1 vote
1 answer
367 views

Regression analysis with max value

I am trying to find the best curve that will describe my data. my data are stored in numpy arrays of t and dur they are both in ...
Tomáš Ulrich's user avatar
7 votes
8 answers
3k views

Statistically compare two large continuous datasets

I have multiple images with 1 band/channel. This of an RGB image, then I only have the blue band/channel. In other words, multiple 1D datasets, or multiple 1D arrays. I would like to statistically ...
user88484's user avatar
  • 227
1 vote
1 answer
2k views

Gradient of a multivariate function numpy

I'm trying to calculate the gradient of multivariate function g using NumPy. g = lambda w: -np.sin(np.pi*np.sum(w**2)) + np.log(np.sum(w**2)) ...
Oguz Aktas's user avatar
1 vote
0 answers
806 views

Positive semi definite matrix with negative eigenvalues?

From what I know, for any square real matrix A, a matrix generated with the following should be a positive semidefinite (PSD) matrix: ...
JAEWON LEE's user avatar
1 vote
0 answers
55 views

Working with sparse data in numpy and sklearn [closed]

I have a time series dataset geenrated from some electrophysiological data. I have a frequncy dataset and the matrix is quite sparse but huge, like it contains 0.005 s time bins for 2000+ neurons ...
Angus Campbell's user avatar
0 votes
0 answers
569 views

RMSE, MAE and MAPE reduced but RMSPE increased after removing outliers in linear regression

I am using a linear regression model with 465 datapoints to predict crop yield of wheat. The data points are spilt into training and testing sets in 80:20 ratio. Initially, I tried linear regression ...
kakashiOfSharingan's user avatar
0 votes
0 answers
78 views

Sklearn PCA projection differences while reproducing projection sample by sample

I've been stuck on this issue due to inability to reproduce the performance of PCA-classification pipeline on training data, but in case the pipeline receives one sample at a time. This seems to be ...
Mateusz Łukasik's user avatar
1 vote
0 answers
170 views

How do I get the stationary distribution of a Markov chain matrix from SVD?

I have a matrix that represents a Markov chain. ...
Jane Wayne's user avatar
  • 1,399
1 vote
0 answers
64 views

Probability of drawing N elements from M elements with per element draw probability without replacement

I have a list of M elements with per element draw probability, summing to 1.0. Example (M=10): L = [0.3, 0.2, 0.01, 0.05, 0.02, 0.02, 0.2, 0.05, 0.05, 0.1] Now I ...
CreeperPower storing's user avatar
0 votes
1 answer
1k views

How to sample from non-gaussian dataset [duplicate]

Let's say I have a small dataset (normalized), that doesn't necessarily follow a gaussian distribution. We can see that by plotting it on a simple histogram. There is clearly a bias. There is also a ...
user avatar
0 votes
2 answers
129 views

I'm performing a multi linear regression on the The Oxford Covid-19 Government Response Tracker. I have a couple of doubts about the process

I hope this is the right place to ask this. I'm currently working my way through a dataset and performing Multiple Linear Regression on it. The data is for Oxford Governement Response Tracker for the ...
Vipul Dass's user avatar
1 vote
1 answer
354 views

Behaviour of intralayer (lateral) connections in neural network during training

I am interested in experimenting with some very simple neural network architectures by building them in numpy. I have followed a course in how to build a feed-forward multilayer neural network in ...
Geodatsci's user avatar
0 votes
1 answer
11k views

How can i get the phase difference between two frequencies?

I have two signals of the same frequency. Both have frequencies of 13.56Mhz, and I want to find the phase difference between these two frequencies. The function generator generates a sinusoidal ...
user avatar
4 votes
2 answers
4k views

How to sample from truncated distributions using scipy?

I have min and max values for certain variables such as: Expenses Loss Growth I'd like to add a distribution around them and plot a histogram in python. Distribution could be beta, gamma right type ...
kms's user avatar
  • 560
0 votes
0 answers
483 views

How to create and solve a underdetermined nonlinear system of equations using python

as i already mentioned in the header my plan is to create and solve a system of nonlinear equations in python. As I also mentioned, the equations system will be underdetermined. I will try to give an ...
David_D's user avatar
2 votes
1 answer
112 views

Standard deviation cap crosses zero

Let's say I have some reference data and some predicted data and I want to show the standard deviation of the mean absolute error. When I create error bar using numpy and matplotlib, errorbar crosses ...
Chruz Roman's user avatar
0 votes
1 answer
1k views

In Python, can I use mean, median, minimum, maximum, standard deviation, population size, and single sample to generate statistically identical data?

Example situation After each exam, the professor provides the following information. Minimum Score [Arithmetic] Mean Median Maximum Score Standard Deviation I also know what my score was as well as ...
Nik's user avatar
  • 1
0 votes
0 answers
178 views

Visualize PCA, train or test?

I am new to PCA and have a question about visualization when it comes to fitting and transposing. I have two data, which are train and test. Here are four methods: ...
mjf88530's user avatar
0 votes
0 answers
32 views

What I have this rare output value of variance and standart deviation functions in numpy? [duplicate]

Hell i have nonsense values of variance and standart deviation in numpy. this documentation no make sense with this sample. https://numpy.org/doc/stable/reference/generated/numpy.std.html youtube ...
rubengavidia0x's user avatar
0 votes
1 answer
2k views

When does MAPE (Mean Absolute Percentage Error) fail?

I have a multioutput regression model that predicts float values. When using MAPE to evaluate regression model performance (using either built in libraries or implementing a function for it) I am ...
Jebathon's user avatar
  • 101
1 vote
1 answer
1k views

Numpy.cov() in Python returning a matrix of NaN's instead of 0's [closed]

The cov() method from the numpy library returns a covariance matrix where columns represent different features and rows represent separate instances of the same feature. Therefore, passing a nx1 ...
user3163829's user avatar
1 vote
0 answers
879 views

Numpy and Statmodel issue - LinAlgError - Singular Matrix

I have seen other topics on this, but I couldn't get their solutions working for me. Perhaps someone else will know why. namely: statsmodels: error in kde on a list of repeated values However, my ...
LeFraf's user avatar
  • 111
0 votes
1 answer
185 views

Stats Model contingency table, unable to reshape data and run test for nd array 2 x 2 x k

Consider below list of 2×2 tables and CMH (Cochran–Mantel–Haenszel) test results. We are trying to determine if each specific centre was associated with the success of the treatment [Data from Agresti,...
Francisco's user avatar
  • 125
0 votes
0 answers
392 views

How to find out the interval within which probability of sample mean lying within $\pm a$ units of population mean is $0.95$ using Python?

I am a beginner in the field of statistics and data science, so request you to treat me kindly. I have to solve the following problem in python: Suppose the population variable $X$ is $\text{N}(3, 0....
user310070's user avatar
3 votes
2 answers
2k views

Proper shape of LSTM dataset for keras

I understand that similar questions have been asked before, but they are all based on specific examples. I want to consider a very simple example: we have a sequence of 1000 numbers, and want an LSTM ...
Thomas Wagenaar's user avatar
1 vote
1 answer
2k views

How to find the percentage of values within a given range?

I am a beginner in the field of statistics and data science, so request you to treat me kindly. Problem statement - Variable X has a mean of 15 and a standard deviation of 2. What is the minimum ...
user309987's user avatar
0 votes
1 answer
632 views

Bounds for samples from the normal distribution using numpy.random.randn

I am new to both stats and scientific Python, so apologies if this question breaches any guidelines. I want to know what x = np.random.randn(500) actually does, in ...
Robin Andrews's user avatar
1 vote
1 answer
184 views

Probability of a point taken from a certain normal distribution will be less than or equal to than a point taken from another?

Suppose we have two independent normal distributions How do I calculate the probability of a certain point taken from distribution X1 being less than or equal to a ...
Milind Dalvi's user avatar
4 votes
1 answer
6k views

How does numpy generate samples from a beta distribution?

numpy lets you generate random samples from a beta distribution (or any other arbitrary distribution) with this API: ...
eggie5's user avatar
  • 163
1 vote
1 answer
201 views

Clarification needed on gradients in backpropagation

I was going through this book "Practical Convolutional Neural Networks" and there under the backpropagation section, it demonstrates calculating the gradient for ...
Shiladitya Bose's user avatar
0 votes
2 answers
788 views

Generating statistical distributions and sorting them

I am creating two distributions as shown below. ...
user963241's user avatar
1 vote
0 answers
42 views

Generating correlated samples from bernoulli variables [duplicate]

I am trying to implement a program that samples from two identically distributed Bernoulli random variables, $X_1$ and $X_2$, such that they have a specific correlation coefficient, $\rho$. I found a ...
synack's user avatar
  • 371
2 votes
2 answers
5k views

Violin plot of 2 numpy arrays with seaborn

I would like to compare the distribution of 2 numpy arrays using a violin plot made with seaborn. The maximal value in both arrays is 1. The plot suggests a higher maximum. Am I misunderstanding the ...
Guido Cattani's user avatar
0 votes
0 answers
34 views

Neural network from scratch: only predicts training inputs correctly [duplicate]

Here is a neural network I've been working on. It takes in an array of four zeros or ones and predicts whether that pattern of zeros and ones is a backslash. ...
Joey's user avatar
  • 1