1

I have a train_data which holds information about Stores and their sales. Which looks like this enter image description here

I want to build a multiple feature linear regression to predict the 'Sales' on a test_data, by using 'DayofWeek', 'Customers', 'Promo'.

How do I build a Multiple Linear Regression Model for this, preferably by using SKlearn.

edit: here's the link to the dataset I am using, if anyone is interested : https://www.kaggle.com/c/rossmann-store-sales

This is what i've tried so far.

import pandas as pd

from sklearn import linear_model

x=train_data[['Promo','Customers','DayOfWeek']]

y=train_data['Sales']

lm=LinearRegression()


lm.fit(x,y)

For which i am getting an error saying 'LinearRegression not defined'.

2

2 Answers 2

1

You aren't actually importing the LinearRegression class. If you want to import everything in the linear_model module (which is generally frowned upon) you could do:

from sklearn.linear_model import *
lr = LinearRegression()
...

A better practice is to import the module itself and give it an alias. Like so:

import sklearn.linear_model as lm
lr = lm.LinearRegression()
...

Finally you could import just the class you want:

from sklearn.linear_model import LinearRegression
lr = LinearRegression()
...
Sign up to request clarification or add additional context in comments.

Comments

0

You've imported linear_model, which is the module that contains the LinearRegression() class. To call the LinearRegression class use this:

lm = linear_model.LinearRegression()
lm.fit(x,y)

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.