0

I am new to all this. Likely may have configuration problem.

import pandas as  pd

import matplotlib
import matplotlib.pyplot as plt 
import numpy  as np
%matplotlib inline 
from sklearn.model_selection import train_test_split

from sklearn.metrics import classification_report, accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
import seaborn as sns 

from numpy import matrix
logisticreg = LogisticRegression()
logisticreg.fit(xtrain, ytrain)

Returns

File ...\Python\Python312\Lib\site-packages\sklearn\linear_model\_logistic.py:1303, in LogisticRegression.fit(self, X, y, sample_weight)
   1300 else:
   1301     n_threads = 1
-> 1303 fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, prefer=prefer)(
   1304     path_func(
   1305         X,
   1306         y,
   1307         pos_class=class_,
   1308         Cs=[C_],
...
-> 1871     if isinstance(a, np.matrix):
   1872         return asarray(a).ravel(order=order)
   1873     else:


AttributeError: module 'numpy' has no attribute 'matrix'

Running numpy version 1.26.2

Tried running example

import numpy as np
from sklearn.linear_model import LinearRegression
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
# y = 1 * x_0 + 2 * x_1 + 3`
y = np.dot(X, np.array([1, 2])) + 3
reg = LinearRegression().fit(X, y)
reg.score(X, y)
reg.coef_
reg.intercept_
reg.predict(np.array([[3, 5]]`))

Same error

5
  • 1
  • Do you have a file named numpy.py, which Python is importing instead of the numpy library? Commented Dec 12, 2023 at 23:51
  • I have a numpy.py in ...\AppData\Local\miniconda3\envs\myenv\Lib\site-packages\pandas\core\arrays. Commented Dec 13, 2023 at 21:39
  • I have a numpy.py in ...\AppData\Local\miniconda3\envs\myenv\Lib\site-packages\pandas\core\arrays. </br> I have Anaconda3 installed but I couldn't get that to work at all. Note the machine I am used in sitting behind a firewall. Access the the world is extremely limited.</br> Also what I have noticed is that I can see np.matrix. That appears to be valid in the jupyter notebook. Also I am using VSCode. @Ian Thompson Commented Dec 13, 2023 at 21:47
  • I was able to get the example code to run successfully. There was an extra ` in the last line of code. Commented Dec 14, 2023 at 14:44

1 Answer 1

1

I think I figured out what the problem was. The data object I passed in was not well formed. Correcting that seem to resolve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.