Reputation: 21
AttributeError: `np.NINF` was removed in the NumPy 2.0 release. Use `-np.inf` instead.
This error pops up when running my program. Here is a snippet of my code that isn't working.
def feature_select_fit(x,y,k):
linearreg = LinearRegression()
forward = SequentialFeatureSelector(linearreg,
k_features=k,
forward=True,
scoring='neg_mean_squared_error',
cv=None)
sff = forward.fit(x, y)
feat_names_f = list(sff.k_feature_names_)
print('feat_names_f:',feat_names_f)
print('forward indices:',sff.k_feature_idx_)
print('forward score:',sff.k_score_)
x = sm.add_constant((x[feat_names_f]))
fit = sm.OLS(y,x).fit()
print(fit.summary())
plt.plot(y, fit.fittedvalues, '^')
plt.plot(y, y, 'k-')
plt.xlabel('Actual')
plt.ylabel('Predicted')
plt.title(str(x.columns[1:4])[7:-18])
plt.show()
col = list(x)
for i in col:
plt.plot(x[i],y,'.', label = 'Actual')
plt.plot(x[i],fit.fittedvalues, 'r.', label = 'Predicted')
plt.xlabel(str(i))
plt.ylabel('Recovery')
plt.title('Recovery/'+str(i))
plt.legend()
plt.show()
print('Coefficient of Variation='+str(CV))
print('Auto Correlation='+str(acc))
return
feature_select_fit(X, y, 4)
This function is to take X, our independent variables/features in the form of a pandas dataframe, y, our dependent/target variable and a pandas series and create the best linear regression equation with the specified number of terms. It uses SequentialFeatureSelector to perform forward stepwise regression to filter through all of the columns or variables in X. It then makes a bunch of plots.
Yesterday I created a new environment in Anaconda to work on this project and downloaded the latest release of Python in the same day. I am not sure which of the two caused my issue, but I think it was one of the two. As a result I had to reinstall a bunch of my python packages including numpy and mlxtend. When I went to run this program that I had working two days ago it threw this error
AttributeError: `np.NINF` was removed in the NumPy 2.0 release. Use `-np.inf` instead.
I searched and searched my document for 'np.NINF' and it isnt there. It must be part of a package. I figured that this was due to a package dependency, probably mlxtend or sklearn, not being compatible with the latest numpy. I thought this might be a simple fix if I just uninstall numpy 2.0 and reinstall the numpy version that is supported by the other packages that I am using. I ran a command to see the different packages that mlxtend needs and sure enough it said that it requires numpy>=1.16.2. I understand that it states 1.16.2 or greater so 2.0 should work but I'm not too sure. In my attempt to install the earlier version of numpy using the following commands in my command prompt:
pip uninstall numpy
pip install numpy==1.16.2
It gave the error in the screenshot:
I don't know why my machine 'Failed building wheel for numpy even though I have installed and updated wheel, pip, and setuptools. After that I came here.
I am pretty new to programming and python and this is my first stack overflow question, but I couldn't find any questions or anything online to help me answer my question, probably because numpy 2.0 just came out two days ago I think. If you could help me know where I am thinking wrong, then that would be extremely helpful. I am not sure if it is my package dependencies nor the resaon for my computer not being able to install an older numpy. If I could just get this feature_select_fit function working again that would be great.
Upvotes: 1
Views: 617
Reputation: 21
Instead of attempting to install numpy 1.16.2, I installed the latest release, 1.26.4, prior to 2.0 and now it works. This would have been the version that I previously was using.
Upvotes: 1