-2
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import math
rd=pd.read_csv('homeprices.csv')
a=rd.iloc[:-1]
median_bedrooms=math.floor(a.bedrooms.median())
median_bedrooms
rd.bedrooms=rd.bedrooms.fillna(median_bedrooms)
rd
reg=LinearRegression()

After this i'm getting an bellow error:

    AttributeError                            Traceback (most recent call last)
<ipython-input-25-a53be8969e13> in <module>
----> 1 reg=linear_model.linearRegression()

AttributeError: module 'sklearn.linear_model' has no attribute 'linearRegression'

How can i fix this bug now?

Gambler Aziz
  • 41
  • 1
  • 10
  • Your call is wrong, you already imported the class so use it like `reg=LinearRegression()` – molybdenum42 Oct 31 '19 at 10:26
  • i did but same error is comming again, Now what shall i do? – Gambler Aziz Oct 31 '19 at 10:31
  • Uninstall and reinstall sklearn – Bharath M Shetty Oct 31 '19 at 10:32
  • i'm using pandas. sklearn is preinstalled in it. – Gambler Aziz Oct 31 '19 at 10:33
  • Uninstall and reinstall refer this docs sklearn https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html – nithin Oct 31 '19 at 10:36
  • Works fine for me on my machine. Are you sure there are no typos etc? – molybdenum42 Oct 31 '19 at 10:40
  • i'm 100% sure..i checked 10 times each and every single line of code. – Gambler Aziz Oct 31 '19 at 10:42
  • You don't have sklearn installed in your system , Your comment " I am using Pandas sklearn is preinstalled in it doesn't make any sense" See below for Pandas dependencies and sklearn dependencies https://pandas.pydata.org/pandas-docs/stable/install.html https://scikit-learn.org/stable/install.html can you reconfirm sklearn is installed – nithin Oct 31 '19 at 10:42
  • but i run the code above link that you provided is working correctly. but in my code is showing error ..how??? – Gambler Aziz Oct 31 '19 at 10:47
  • 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) .......#This code is working finely – Gambler Aziz Oct 31 '19 at 10:47
  • Please edit your question to include the example code that works well. Also, make sure to copy the traceback given from the code shown (the current traceback does not match the code). – Itamar Mushkin Oct 31 '19 at 11:14

1 Answers1

2

I don't have enough reputation to comment, but in your traceback you have

reg=linear_model.linearRegression()

This command does not appear anywhere in your question. Indeed, if this is what you wrote, it should be LinearRegression, not linearRegression

ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65