Python Forum
Linear regression doubt - Urgent
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear regression doubt - Urgent
#1
Please clarify below error and support me to resolve this

My code is:

import pandas as pd
import numpy as np
from sklearn import linear_model
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
data=pd.read_excel('C:/Users/Kumaran TS/Desktop/Jupyter prg/Tensile.xlsx')
data
x=data['Hardness'].values.reshape(-1,1)
y=data['Tensile strength'].values.reshape(-1,1)
x_train,x_test,y_train,y_test = train_test_spilt(x,y,test_size=0.2,random_state=80)
Error is:

Error:
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-6-ce5307eca8bb> in <module> 1 x=data['Hardness'].values.reshape(-1,1) 2 y=data['Tensile strength'].values.reshape(-1,1) ----> 3 x_train,x_test,y_train,y_test = train_test_spilt(x,y,test_size=0.2,random_state=80) NameError: name 'train_test_spilt' is not defined
Reply
#2
the error is clear. name train_test_spilt is not defined. Where does it supposedly come from? It looks like you need to import it from sklearn.model_selection
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Sorry buran...next time I will follow your instruction post queries in right way.

Yes. to answer your question. It is called from this command. I had missed out in my posting.

from sklearn.model_selection import train_test_split

Still it is not working
Reply
#4
(May-05-2020, 01:15 PM)kumarants Wrote: Still it is not working


that's not very helpful. post the full traceback you get, in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Please find the below full program with error. Please support to fix it

import pandas as pd
import numpy as np
from sklearn import linear_model
import statsmodels.api as sm
from sklearn.metrics import mean_squared_error
data=pd.read_excel('C:/Users/Kumaran TS/Desktop/Jupyter prg/Tensile.xlsx')
from sklearn.model_selection import train_test_split
x=data['Hardness'].values.reshape(-1,1)
y=data['Tensile strength'].values.reshape(-1,1)
x_train,x_test,y_train,y_test = train_test_spilt(x,y,test_size=0.2,random_state=80)
Error:
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-12-70b6210ad150> in <module> 8 x=data['Hardness'].values.reshape(-1,1) 9 y=data['Tensile strength'].values.reshape(-1,1) ---> 10 x_train,x_test,y_train,y_test = train_test_spilt(x,y,test_size=0.2,random_state=80) NameError: name 'train_test_spilt' is not defined
Reply
#6
you have a typo train_test_spilt
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Big Grin Thanks a lot...simple typo mistake...and really thanks for your timely swift support.

I am basically hardcore mechanical engg...heading India Region LEAN & 6Sigma function in an automotive company.Just start exploring data science and Industry 4.0 learning during this lock-down period.making step by step progress...once again thanks for quick response.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple linear regression with interaction summary table Andrzej_Andrzej 0 289 Feb-21-2024, 07:44 AM
Last Post: Andrzej_Andrzej
  Doubt in Linear Reg by 'MLE' method kumarants 2 1,881 May-08-2020, 12:52 PM
Last Post: kumarants
  Doubt in Linear Reg - "random_state" kumarants 1 1,697 May-05-2020, 06:42 PM
Last Post: buran
  prediction using linear regression (extrapolation?) in a loop karlito 0 3,216 Feb-05-2020, 10:56 AM
Last Post: karlito
  Linear Regression on Time Series karlito 5 3,881 Jan-28-2020, 10:02 AM
Last Post: buran
  How to build linear regression by implementing Gradient Descent using only linear alg PythonSpeaker 1 2,185 Dec-01-2019, 05:35 PM
Last Post: Larz60+
  Linear Regression Python3 code giving weird solutions deepsen 0 1,434 Nov-01-2019, 12:06 PM
Last Post: deepsen
  What is wrong with this implementation of the cost function for linear regression? JoeB 1 3,203 Dec-23-2017, 10:05 AM
Last Post: buran
  help on exponential smoothing and linear regression hkyeung 1 3,130 Sep-02-2017, 09:31 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020